php7.0とphp7.1の違い

1. 型宣言

function type_defined(int $argument) : string {
	return 'Hello';
}

あまり見ない気がしますが。。

$name_list = [
	'luna',
	'sunny',
	'star',
];

function type_defined(int $name_id) : string {
	return isset($name_list[$name_id]) ? $name_list[$name_id] : null; 
}

var_dump(get_name(4));

barryvdh/laravel-debugbar

debuggerはlaravel開発に役立つらしい

ただし、パスワードも丸見えになるらしい。
[vagrant@localhost tea]$ php composer.phar require barryvdh/laravel-debugbar
Using version ^3.2 for barryvdh/laravel-debugbar
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
– Installing maximebf/debugbar (v1.15.0): Downloading (100%) – Installing barryvdh/laravel-debugbar (v3.2.4): Downloading (100%)
maximebf/debugbar suggests installing kriswallsmith/assetic (The best way to manage assets)
maximebf/debugbar suggests installing predis/predis (Redis storage)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover –ansi
Discovered Package: barryvdh/laravel-debugbar
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
Package manifest generated successfully.

league/flysystem-aws-s3-v3

LaravelのファイルストレージとS3を連携させるには、専用のパッケージを導入する必要があるとのこと。

composer.json

"require": {
        "php": "^7.1.3",
        "barryvdh/laravel-dompdf": "^0.8.4",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0"
    },

ここに、league/flysystem-aws-s3-v3を追加する。

laravel/config/filesystem

's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

env(${})となっているので、.envファイルで編集します。

AWS_KEY=[アクセスキー]
AWS_SECRET=[シークレットキー]
AWS_REGION=[リージョン(東京ならap-northeast-1)]
AWS_BUCKET=[バケット名]

そういうことかー

laravelcollective

composer require laravelcollective/html

む? なんだ、laravelcollectiveとは?
https://laravelcollective.com/

>セレクトボックスの組み立てやチェックボックスの初期状態の指定、CSRF対策のトークン埋め込みなどが簡単にできる
う~ん、使うのか?必要性があれば使いますかね。

Stack Overflowで質問しよう

Teratailで質問するより、stack overflowで世界に聞いた方が生産的なような気がしてきた。
ということで、stack overflowで質問してみます。

How to upgrade Laravel 5.2 → 5.8

When upgrading laravel from 5.2 to 5.8, do I need to upgrade one by one each with 5.3, 5.4, 5.5, 5,6, 5.7, 5.8, and check each details of changes?
Or can I go to 5.8 at once by composer json upgrade?
I would like to know general upgrade method of Laravel 5.2 → 5.8?

https://readouble.com/laravel/5.3/en/upgrade.html
https://readouble.com/laravel/5.4/en/upgrade.html
https://readouble.com/laravel/5.5/en/upgrade.html
https://readouble.com/laravel/5.6/en/upgrade.html
https://readouble.com/laravel/5.7/en/upgrade.html
https://readouble.com/laravel/5.8/en/upgrade.html

うん、こっちの方が英語のコミュニケーションの勉強にもなるし、よさそう。

早く気づけば良かった。。

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] [–] []…

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