laravelの.envでsmtpを設定

# 初期値

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

# mailtrap.ioから、usernameとpasswordを取得して.envを編集
# password reset buttonを押下

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required

う。。。

# キャッシュクリア
[vagrant@localhost angel]$ php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!

# 再度password reset buttonを押下

# mailtrapで確認

なるほど。

Laravel 5’s Soft delete

Laravel 5’s Eloquent has a function called SoftDeletes that performs logical deletion instead of physically deleting data from a DB table.

If you do this soft delete, data will not be deleted from the table but it will not be able to be pulled by ordinary SELECT etc. It will behave the same as deleting it.
This function allows you to extract information once it is deleted, when it is needed again.

なるほどー、これ結構便利かも。

use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Eloquent {
	use SoftDeletes;

	protected $dates = ['deleted_at'];
}

モデルに上記のように記述を追加し、SoftDeletesを使えるようにする。削除された場合は、deleted_atカラムにタイムスタンプがセットされる。

なるほどね。

config/app.php

'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,

        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
        Barryvdh\DomPDF\ServiceProvider::class,

    ],

aliases

'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,
        'PDF' => Barryvdh\DomPDF\Facade::class,

    ],

[vagrant@localhost tea]$ php artisan vendor:publish –provider=”Barryvdh\DomPDF\ServiceProvider”
Copied File [/vendor/barryvdh/laravel-dompdf/config/dompdf.php] To [/config/dompdf.php]
Publishing complete.

なんじゃこりゃーーーーーーーーーーーー??

proc_open(): fork failed – Cannot allocate memory

proc_open(): fork failed – Cannot allocate memory が出た時。

swapファイルを作ってやりましょう。
[vagrant@localhost tea]$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 7.91221 s, 136 MB/s
[vagrant@localhost tea]$ /sbin/mkswap /var/swap.1
/var/swap.1: 許可がありません
[vagrant@localhost tea]$ sudo /sbin/mkswap /var/swap.1
スワップ空間バージョン1を設定します、サイズ = 1048572 KiB
ラベルはありません, UUID=984427a6-99bf-434c-ad6b-ea90be7f2670
[vagrant@localhost tea]$ sudo /sbin/swapon /var/swap.1
[vagrant@localhost tea]$ php composer.phar require barryvdh/laravel-dompdf
Using version ^0.8.4 for barryvdh/laravel-dompdf
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
– Installing sabberworm/php-css-parser (8.1.0): Loading from cache
– Installing phenx/php-svg-lib (v0.3.2): Downloading (100%)
– Installing phenx/php-font-lib (0.5.1): Downloading (100%)
– Installing dompdf/dompdf (v0.8.3): Downloading (100%)
– Installing barryvdh/laravel-dompdf (v0.8.4): Downloading (100%)
dompdf/dompdf suggests installing ext-imagick (Improves image processing performance)
dompdf/dompdf suggests installing ext-gmagick (Improves image processing performance)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover –ansi
Discovered Package: barryvdh/laravel-dompdf
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision

うむー なんだかなー

laravelにpdfのモジュールを入れよう

[vagrant@localhost tea]$ php artisan -V
Laravel Framework 5.8.11
[vagrant@localhost tea]$ ls
app composer.lock package.json resources tests
artisan composer.phar phpunit.xml routes vendor
bootstrap config public server.php webpack.mix.js
composer.json database readme.md storage
[vagrant@localhost tea]$ php composer.phar require barryvdh/laravel-dompdf
Using version ^0.8.4 for barryvdh/laravel-dompdf
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
– Installing sabberworm/php-css-parser (8.1.0): Downloading (100%)
proc_open(): fork failed – Cannot allocate memory
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class

Installation failed, reverting ./composer.json to its original content.
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

PHP Warning: proc_open(): fork failed – Cannot allocate memory in phar:///home/vagrant/local/app/laravel/tea/composer.phar/vendor/symfony/console/Application.php on line 952

Warning: proc_open(): fork failed – Cannot allocate memory in phar:///home/vagrant/local/app/laravel/tea/composer.phar/vendor/symfony/console/Application.php on line 952

[ErrorException]
proc_open(): fork failed – Cannot allocate memory

require [–dev] [–prefer-source] [–prefer-dist] [–no-progress] [–no-suggest] [–no-update] [–no-scripts] [–update-no-dev] [–update-with-dependencies] [–update-with-all-dependencies] [–ignore-platform-reqs] [–prefer-stable] [–prefer-lowest] [–sort-packages] [-o|–optimize-autoloader] [-a|–classmap-authoritative] [–apcu-autoloader] [–] []…

なにいいいいいいいいいいいいいいいいいいいいいいい

Laravelでmailを送信する!?

どうやらconfの中の、mail.phpを編集するようだ。

'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),

routs/web.php

Route::get('/', function(){
	$data = [];
	Mail::send('emails.welcome', $data, function($message){
		$message->to('hogehoge@gmail.com')->subject('title')
	});
});

ふーん、こんな感じか。。

Laravel5.7→5.8へのアップグレード

まず例にならって、5.7をcomposerでインストールします。

続いて、あ、その前に、公式ドキュメントを確認しておきましょう。
https://readouble.com/laravel/5.8/ja/upgrade.html

重要度の高い変更
キャッシュ持続時間が秒指定に
キャッシュロックの安全性向上
環境変数のパース
Markdownファイルのディレクトリ変更
Nexmo/Slack通知チャンネル

重要度が中程度の変更
コンテナジェネレーターとタグ付けサービス
SQLiteバージョン制約
ヘルパから文字列と配列クラスへ
遅延サービスプロバイダ
PSR-16準拠
不規則変化する複数形のモデル名
IDが増加するカスタムピボットモデル
Pheanstalk4.0

うーん、キャッシュに関することが多いですな。slackは上場するしねー
さて、composer.json

"license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0"
    },

はい、それでは、composerをアップデートします。

[vagrant@localhost tea]$ cp ../composer.phar composer.phar
[vagrant@localhost tea]$ php composer.phar update
[vagrant@localhost tea]$ php artisan --version
Laravel Framework 5.8.11

きたーーーーーーーーーーーー とりあえずお疲れ!
一仕事終わったので、サウナ行ってきます^^

laravel5.6→5.7へアップグレード

とりあえずアップグレードガイドのマニュアルを見てみる。
https://laravel.com/docs/5.7/upgrade

毎度のことながら、5.6.* →5.7.* に変更
composer.json


“require”: {
“php”: “^7.1.3”,
“fideloper/proxy”: “^4.0”,
“laravel/framework”: “5.7.*”,
“laravel/tinker”: “^1.0”
},
[/php]

[vagrant@localhost barley]$ cp ../composer.phar composer.phar
[vagrant@localhost barley]$ ls
app composer.lock package.json resources tests
artisan composer.phar phpunit.xml routes vendor
bootstrap config public server.php webpack.mix.js
composer.json database readme.md storage
[vagrant@localhost barley]$ php composer.phar update

[vagrant@localhost barley]$ php artisan –version
Laravel Framework 5.7.28

[vagrant@localhost barley]$ php artisan serve –host 192.168.35.10 –port 8000
Laravel development server started:
[Sun Apr 14 16:15:25 2019] 192.168.35.1:65342 [200]: /favicon.ico

はあああああああああああああ?????
なんだこれ?

laravel5.5→5.6 設定ファイルの変更・新規作成・削除

設定ファイル
laravel/app/Http/Middleware/TrustProxies.php ※変更

// protected $headers = [
    //     Request::HEADER_FORWARDED => 'FORWARDED',
    //     Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
    //     Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
    //     Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
    //     Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
    // ];
    protected $headers = Request::HEADER_X_FORWARDED_ALL;

laravel/config/hashing.php ※新規

return [
'driver'=>'argon',
];

laravel/config/logging.php ※新規

return [

'default'=>env('LOG_CHANNEL', 'stack'),

'channels' => [
 'stack'=> [
 	'driver'=>'stack',
 	'channels'=>['daily'],
 ],

 'single'=>[
 	'driver'=>'single',
 	'path'=> storage_path('logs/laravel.log'),
 	'level'=>'debug',
 ],

 'daily'=>[
 	'driver'=>'daily',
 	'path'=>storage_path('logs/laravel.log'),
 	'level'=>'debug',
 	'days'=> 30,
 ],

 slack=>[
 	'driver'=>'slack',
 	'url'=>env('LOG_SLACK_WEBHOOK_URL'),
 	'username'=>'Laravel_log',
 	'emoji'=>'.boom:',
 	'level'=>'critical',
 ],

 'syslog'=>[
 	'driver'=>'syslog',
 	'level'=>'debug',
 ],

 'errorlog'=>[
 	'driver'=>'errorlog',
 	'level'=>'debug',
 ],
],

];

laravel/config/app.php ※コメントアウト

// 'log' => env('APP_LOG', 'single'),
    // 'log_level' => env('APP_LOG_LEVEL', 'debug'),

[vagrant@localhost blog]$ php artisan serve –host 192.168.35.10 –port 8000
PHP Notice: Use of undefined constant slack – assumed ‘slack’ in /home/vagrant/local/app/laravel/blog/config/logging.php on line 25
Laravel development server started:
[Sun Apr 14 15:33:10 2019] PHP Notice: Use of undefined constant slack – assumed ‘slack’ in /home/vagrant/local/app/laravel/blog/config/logging.php on line 25
[Sun Apr 14 15:33:12 2019] PHP Notice: Use of undefined constant slack – assumed ‘slack’ in /home/vagrant/local/app/laravel/blog/config/logging.php on line 25
[Sun Apr 14 15:33:13 2019] 192.168.35.1:61897 [200]: /favicon.ico

これはやらんとわからんなー

The following exception is caused by a lack of memory or swap, or not having swap configured

The following exception is caused by a lack of memory or swap, or not having swap configured
なにこれ?

[vagrant@localhost blog]$ free -m
total used free shared buffers cached
Mem: 490 140 349 0 2 31
-/+ buffers/cache: 106 383
Swap: 991 658 333

swapは割り当てあります。
そもそもスワップファイルとは??
->使っていないメモリの内容を一時的にしまっておくためのファイル

スワップファイルを作成します
[vagrant@localhost blog]$ sudo -s /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 2.82202 s, 380 MB/s
[vagrant@localhost blog]$ sudo -s /sbin/mkswap /var/swap.1
スワップ空間バージョン1を設定します、サイズ = 1048572 KiB
ラベルはありません, UUID=e033e359-3fb0-4007-872a-73fc1e07ea10
[vagrant@localhost blog]$ sudo -s /sbin/swapon /var/swap.1

[vagrant@localhost blog]$ php composer.phar update
[vagrant@localhost blog]$ php artisan –version
Laravel Framework 5.6.39

おおおおおおおおおおおおおおおおおおおおおおおお
毎回リアクションが一緒になってきた。。