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

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

laravel5.5を入れて5.6へcomposer update

[vagrant@localhost laravel]$ php composer.phar create-project laravel/laravel blog “5.5.*”

[vagrant@localhost blog]$ php artisan –version
Laravel Framework 5.5.45
[vagrant@localhost blog]$ php -v
PHP 7.1.21 (cli) (built: Aug 15 2018 18:11:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

composer.json

"require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0",
        "olssonm/l5-very-basic-auth":"5.*"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~7.0",
        "symfony/thanks": "^1.0"
    },

[vagrant@localhost blog]$ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 22 updates, 3 removals
– Removing symfony/polyfill-php70 (v1.11.0)
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/blog/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/blog/composer.phar/vendor/symfony/console/Application.php on line 952

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

update [–prefer-source] [–prefer-dist] [–dry-run] [–dev] [–no-dev] [–lock] [–no-custom-installers] [–no-autoloader] [–no-scripts] [–no-progress] [–no-suggest] [–with-dependencies] [–with-all-dependencies] [-v|vv|vvv|–verbose] [-o|–optimize-autoloader] [-a|–classmap-authoritative] [–apcu-autoloader] [–ignore-platform-reqs] [–prefer-stable] [–prefer-lowest] [-i|–interactive] [–root-reqs] [–] []…

composer.jsonを編集

php
>=5.6.4 → >=7.0.0
laravel/framework
5.4.* → 5.5.*
phpunit/phpunit
~5.0 → ~6.0
require-devセクション
filp/whoopsパッケージ(バージョン~2.0)を追加
scriptsセクション
post-autoload-dumpイベントへpackage:discoverコマンドを追加

"require": {
        "php": ">=7.0.0",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0"
    },
"require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "filp/whoops":"~2.0",
        "phpunit/phpunit": "~6.0"
    },


"post-autoload-dump":[
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]

[vagrant@localhost laravel]$ ls
blog composer.phar
[vagrant@localhost laravel]$ cp composer.phar blog/composer.phar
[vagrant@localhost laravel]$ cd blog
[vagrant@localhost blog]$ 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 blog]$ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 13 updates, 1 removal
– Removing symfony/yaml (v4.2.5)
– Updating paragonie/random_compat (v2.0.18 => v9.99.99): Loading from cache
– Installing symfony/polyfill-php72 (v1.11.0): Downloading (100%)
– Installing symfony/polyfill-intl-idn (v1.11.0): Downloading (100%)
– Installing symfony/polyfill-iconv (v1.11.0): Downloading (100%)
– Installing doctrine/lexer (v1.0.1): Loading from cache
– Installing egulias/email-validator (2.1.7): Downloading (100%)
– Updating swiftmailer/swiftmailer (v5.4.12 => v6.2.0): Downloading (100%) – Installing psr/simple-cache (1.0.1): Loading from cache
– Installing psr/container (1.0.0): Loading from cache
– Updating laravel/framework (v5.4.36 => v5.5.45): Downloading (100%)
– Updating sebastian/recursion-context (2.0.0 => 3.0.0): Loading from cache
– Installing sebastian/object-reflector (1.1.1): Loading from cache
– Updating sebastian/object-enumerator (2.0.1 => 3.0.3): Loading from cache
– Updating sebastian/global-state (1.1.1 => 2.0.0): Loading from cache
– Updating sebastian/exporter (2.0.0 => 3.1.0): Loading from cache
– Updating sebastian/environment (2.0.0 => 3.1.0): Loading from cache
– Updating sebastian/diff (1.4.3 => 2.0.1): Downloading (100%)
– Updating sebastian/comparator (1.2.4 => 2.1.3): Downloading (100%)
– Updating phpunit/phpunit-mock-objects (3.4.4 => 5.0.10): Downloading (100%) – Installing theseer/tokenizer (1.1.2): Loading from cache
– Updating phpunit/php-code-coverage (4.0.8 => 5.3.2): Downloading (100%) – Installing phar-io/version (1.0.1): Loading from cache
– Installing phar-io/manifest (1.0.1): Loading from cache
– Updating phpunit/phpunit (5.7.27 => 6.5.14): Downloading (100%)
– Installing filp/whoops (2.3.1): Loading from cache
filp/whoops suggests installing whoops/soap (Formats errors as SOAP responses)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Package manifest generated successfully.
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
[vagrant@localhost blog]$ php artisan –version
Laravel Framework 5.5.45

うおおおおおおおおおおおおおおおおおおお
アップデートできたーーーーーーーーーーーーーーーーー
すげーーーーーーーーーーーーーー

続いて、5.5→5.6をやりましょう。

Laravel5.4から5.5へアップグレード

まず、composer.jsonを見てみましょう。

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

ふむ。

Laravel 5.4を入れる

まずcomposerを入れた状態で、
[vagrant@localhost laravel]$ php composer.phar create-project laravel/laravel blog “5.4.*”

replacement was suggested.
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled services file has been removed.
> php artisan key:generate
Application key [base64:hogehoge] set successfully.

[vagrant@localhost laravel]$ ls
blog composer.phar
[vagrant@localhost laravel]$ cd blog
[vagrant@localhost blog]$ php artisan -V
Laravel Framework 5.4.36

vagrant@localhost blog]$ php artisan serve –host 192.168.35.10 –port 8000
Laravel development server started:

おおおおおおおおおおおお、いいねー

Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.

composer.jsonを編集します。

"require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },

updateします。
[vagrant@localhost blog]$ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 0 updates, 27 removals
– Removing webmozart/assert (1.4.0)
– Removing theseer/tokenizer (1.1.2)
– Removing sebastian/version (2.0.1)
– Removing sebastian/resource-operations (2.0.1)
– Removing sebastian/recursion-context (3.0.0)
– Removing sebastian/object-reflector (1.1.1)
– Removing sebastian/object-enumerator (3.0.3)
– Removing sebastian/global-state (2.0.0)
– Removing sebastian/exporter (3.1.0)
– Removing sebastian/environment (4.1.0)
– Removing sebastian/diff (3.0.2)
– Removing sebastian/comparator (3.0.2)
– Removing sebastian/code-unit-reverse-lookup (1.0.1)
– Removing phpunit/phpunit (7.5.8)
– Removing phpunit/php-token-stream (3.0.1)
– Removing phpunit/php-timer (2.1.1)
– Removing phpunit/php-text-template (1.2.1)
– Removing phpunit/php-file-iterator (2.0.2)
– Removing phpunit/php-code-coverage (6.1.4)
– Removing phpspec/prophecy (1.8.0)
– Removing phpdocumentor/type-resolver (0.4.0)
– Removing phpdocumentor/reflection-docblock (4.3.0)
– Removing phpdocumentor/reflection-common (1.0.1)
– Removing phar-io/version (2.0.1)
– Removing phar-io/manifest (1.0.3)
– Removing myclabs/deep-copy (1.9.1)
– Removing doctrine/instantiator (1.2.0)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled class file has been removed.
[vagrant@localhost blog]$ php artisan -V
Laravel Framework version 5.3.31

なぜだあああああああああああああああああ