- 投稿日:2020-02-16T22:50:00+09:00
日本語専用のPHPランダムジェネレータを作りました
- PHPのランダムジェネレータはfzaninotto/Fakerは有名だと思いますが、名前などの日本語バージョンもあります。
- でも、単語、住所、メールなども色々欲しい!
- 無かったので、
fzaninotto/Faker
を利用して、作りました。➡︎ Github⛩
インストール
コンポーザー利用、インストール
composer require xyyo/faker-japanese使い方(ほぼ全ての例)
- 元々日本語特定用の
Faker\Factory::create('ja_JP')
は不要- 全てのロジックは自分のプロバイダーに
以下の例をご覧ください。
<?php // psr-4 クラスのオートロード require_once 'vendor/autoload.php'; $faker = Faker\Factory::create(); $faker->addProvider(new Faker\Provider\Japanese($faker)); // テキスト関連 $faker->color => 薄橙 $faker->kanji => 悠 $faker->word => 給料 $faker->idiom => 画竜点睛 $faker->pokemon => スリーパー $faker->realText => 大きな望遠鏡ぼうえんきょうで銀河ぎんがをよっく調しらべると銀河ぎんがはだいたい何でしょう。 // インターネット関連 $faker->domainName => saito.org $faker->url => www.hiroshi.com $faker->email => hirokawa@yahoo.co.jp $faker->userFirstName => osamu $faker->userLastName => yamada $faker->userName => yamaguchi chiyo // アドレス関連 $faker->bank => 北九州銀行 $faker->postcode => 869-5565 $faker->country => 合衆国領有小離島 $faker->prefecture => 三重県 $faker->ward => 西区 $faker->city => 松本市 $faker->streetAddress => 西之園町3-7-3 $faker->secondaryAddress => 吉田コーポ104号 $faker->address => 佐賀県山口市南区中村町4-5-9 $faker->addressWithCode => 304-6851 奈良県田中市南区佐藤町5-4-3 若松ハイツ105号 // 人間関連 $faker->phone => 00332-8-0234 $faker->company => 有限会社佐々木木材 $faker->lastName => 渡辺 $faker->firstName('male') => 太一 $faker->firstName('female') => 明美 $faker->name('male') => 松本 涼平 $faker->name('female') => 村山 春香 $faker->lastKanaName => ツダ $faker->firstKanaName('male') => ヨウスケ $faker->firstKanaName('female') => モモコ $faker->kanaName('male') => ナカジマ ミツル $faker->kanaName('female') => ナカムラ ハルカLaravel の Factory の使い方
// UserFactory.php $factory->define(User::class, function (Faker $faker) { // add this simple line here $faker->addProvider(new \Faker\Provider\Japanese($faker)); return [ 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, .....tinker ですぐ確認しましょう !
Psy Shell v0.9.12 (PHP 7.3.13 — cli) by Justin Hileman >>> factory(App\User::class,2)->create() => Illuminate\Database\Eloquent\Collection {#3330 all: [ App\User {#3326 name: "宮沢 直人", email: "satomi.xidao@example.org", email_verified_at: "2020-02-17 12:21:38", updated_at: "2020-02-17 12:21:38", created_at: "2020-02-17 12:21:38", id: 5, }, App\User {#3335 name: "大垣 智也", email: "tsubasa08@example.org", email_verified_at: "2020-02-17 12:21:38", updated_at: "2020-02-17 12:21:38", created_at: "2020-02-17 12:21:38", id: 7, }, ], }to do
fzaninotto/Faker
に PR を出す。他のパッケージじゃなくて、やっぱり本家を使いたい気持ちもあるので、時間があれば、
fzaninotto/Faker
にPRを出したい。
少しでも役に立たら、githubの⭐️やコメントは嬉しいです。
- 投稿日:2020-02-16T22:02:50+09:00
Herokuにデプロイしたら画像が突然取得できなくなった
Herokuにデプロイした直後に画像が消える
開発環境:cloud9
言語:PHP7.2
フレームワーク:Laravel 5.5ローカルサーバーでLaravelのプロジェクトを起動していた時はアプリ内で画像は問題なく表示されていました。ちなみにこの時から画像はAWSのS3に保存して取得するようにしていました。アプリの最低限の機能ができたのでherokuへデプロイしてみましたが、画像が一切読み込めなくなりました。おまけに、表示されるエラーが"something went wrong."だけなので困りました。
Herokuのログを確認
とりあえず不具合の原因を探るためにhrokuのログを確認してみました。
$ heroku config:set APP_LOG=errorlog $ heroku logsログを見ると、S3の関連でエラーが出ていることが分かりました。
HerokuにS3用の環境設定をしていなかった
初心者あるあるかもしれませんが、非常に初歩的なミスで、HerokuのconfigファイルにS3の設定を書き込んでいませんでした。というわけで、configファイルにS3の設定を書き込みました。
heroku config:set AWS_ACCESS_KEY_ID=自分のアクセスキーID heroku config:set AWS_SECRET_ACCESS_KEY=S3へのシークレットアクセスキー heroku config:set S3_BUCKET_NAME=S3バケットの名前 heroku config:set AWS_DEFAULT_REGION=AWSのリージョン(バージニア北部ならus-east-1)これで問題なく画像が表示されるようになりました。
- 投稿日:2020-02-16T21:57:06+09:00
Trying to get property of non-object とは
Object(入力欄)に何も入力しないとこのエラーが出ました。
端的には、「そのObjectには、textという(publicに触れる)プロパティはないよ」というエラーメッセージのようです。
つまり、そのObjectにはtext(文字)が何も入ってないですよ、と私なりに解釈しました。「存在しないObject(オブジェクト)のプロパティを呼び出そうとしている」というのがエラーの直訳ですが、私の解釈で合っていますか?
お答えいただければ嬉しいです。
- 投稿日:2020-02-16T20:41:16+09:00
[Laravel 5.6 ~] いつの間にかServiceProvider内でシンプルなbindを行う方法が提供されてた
はじめに
初投稿です。
今まで業務ではlaravel5.5を使っており、最近新規のプロジェクトでlaravel6系統を使うようになったので、色々と変更点を確認しておりました(今更)。
その中で、ドキュメントにひっそりと追記されているにもかかわらず、あまり類似の情報をqiita等で見かけなかった(と思っている)物があったため、備忘録として投稿します。
環境
- laravel 5.6 ~
- ~ 5.5までは対応していません
対象
- Laravelをそれなりに使っていて、DIコンテナ内で抽象と具象のbindについて大枠理解している方
- 本記事ではDIの仕組み、それを使う動機等、「そもそもなぜこんなことをする必要があるか」について理解されている前提です。
基本的なバインド処理
さて、早速ですが基本的なバインド処理についてです。
最も基本的なinterfaceと実装クラスのbindingは以下のようになるかと思います。app/Providers/AppServiceProvider.php<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // 抽象に対して具象クラスをbindingする // 以後、コンストラクタインジェクションやapp()の引数に(Abstract::class)で呼び出すと、Concreteクラスが返却される $this->app->bind(Abstract::class, Concrete::class); dd(Abstract::class); // => Concreteクラスが返却される } /** * Bootstrap any application services. * * @return void */ public function boot() { // } }~ 5.5までのバインド方法
その上で、複数のバインドをまとめて行いたいユースケースについて考えます。
今まで自分が関わってきたプロジェクトで、バインドを複数まとめて行いたいとき(Repository Pattern等)、以下のような書き方をしていました。app/Providers/AppServiceProvider.phpclass AppServiceProvider extends ServiceProvider { /** * bindingするinterfaceと実装クラスを$key => $valueで保持する * * @param array */ private $repositoryBindings = [ FooRepository::class => EloquentFooRepository::class, BarRepository::class => EloquentBarRepository::class, ]; /** * Register any application services. * * @return void */ public function register() { // すべてのbindingを回して登録する foreach($repositoryBindings as $abstract => $concrete) { $this->app->bind($abstract => $concrete); } } /** * Bootstrap any application services. * * @return void */ public function boot() { // } }汚いというわけでもなく、特に問題なく動作するコードです。
5.6からのバインド方法
readoubleにしれっと追記されています。
https://readouble.com/laravel/5.6/ja/providers.htmlシンプルなバインドを行うためのプロパティが追加されており、ここにbindを指定するだけで自動でbindingが行われる様になっています。
(ついでに$singletonのプロパティも用意されています)app/Providers/AppServiceProvider.phpclass AppServiceProvider extends ServiceProvider { /** * 結合したいabstractとconcreteを登録. ここに記述されたものは自動でbindingされる * * @param array */ public $bindings = [ FooRepository::class => EloquentFooRepository::class, BarRepository::class => EloquentBarRepository::class, ]; /** * Register any application services. * * @return void */ public function register() { // ここで何も書かなくても$bindingsに指定があれば自動でbindが行われる } /** * Bootstrap any application services. * * @return void */ public function boot() { // } }終わりに
大きなメリットがあるわけでもなく、ちょっとしたtipsでした。
ただ、やはりフレームワークが用意してくれている方式に乗っかれると気持ちがいいですね。
- 投稿日:2020-02-16T20:41:16+09:00
[Laravel 5.6 ~] ServiceProvider内でシンプルなbindを行う方法が増えてた
はじめに
初投稿です。
今まで業務ではlaravel5.5を使っており、最近新規のプロジェクトでlaravel6系統を使うようになったので、色々と変更点を確認しておりました(今更)。
その中で、ドキュメントにひっそりと追記されているにもかかわらず、あまり類似の情報をqiita等で見かけなかった(と思っている)物があったため、備忘録として投稿します。
環境
- laravel 5.6 ~
- ~ 5.5までは対応していません
対象
- Laravelをそれなりに使っていて、DIコンテナ内で抽象と具象のbindについて大枠理解している方
- 本記事ではDIの仕組み、それを使う動機等、「そもそもなぜこんなことをする必要があるか」について理解されている前提です。
基本的なバインド処理
さて、早速ですが基本的なバインド処理についてです。
最も基本的なinterfaceと実装クラスのbindingは以下のようになるかと思います。app/Providers/AppServiceProvider.php<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // 抽象に対して具象クラスをbindingする // 以後、コンストラクタインジェクションやapp()の引数に(Abstract::class)で呼び出すと、Concreteクラスが返却される $this->app->bind(Abstract::class, Concrete::class); dd(Abstract::class); // => Concreteクラスが返却される } /** * Bootstrap any application services. * * @return void */ public function boot() { // } }~ 5.5までのバインド方法
その上で、複数のバインドをまとめて行いたいユースケースについて考えます。
今まで自分が関わってきたプロジェクトで、バインドを複数まとめて行いたいとき(Repository Pattern等)、以下のような書き方をしていました。app/Providers/AppServiceProvider.phpclass AppServiceProvider extends ServiceProvider { /** * bindingするinterfaceと実装クラスを$key => $valueで保持する * * @param array */ private $repositoryBindings = [ FooRepository::class => EloquentFooRepository::class, BarRepository::class => EloquentBarRepository::class, ]; /** * Register any application services. * * @return void */ public function register() { // すべてのbindingを回して登録する foreach($repositoryBindings as $abstract => $concrete) { $this->app->bind($abstract => $concrete); } } /** * Bootstrap any application services. * * @return void */ public function boot() { // } }汚いというわけでもなく、特に問題なく動作するコードです。
5.6からのバインド方法
readoubleにしれっと追記されています。
https://readouble.com/laravel/5.6/ja/providers.htmlシンプルなバインドを行うためのプロパティが追加されており、ここにbindを指定するだけで自動でbindingが行われる様になっています。
(ついでに$singletonのプロパティも用意されています)app/Providers/AppServiceProvider.phpclass AppServiceProvider extends ServiceProvider { /** * 結合したいabstractとconcreteを登録. ここに記述されたものは自動でbindingされる * * @param array */ public $bindings = [ FooRepository::class => EloquentFooRepository::class, BarRepository::class => EloquentBarRepository::class, ]; /** * Register any application services. * * @return void */ public function register() { // ここで何も書かなくても$bindingsに指定があれば自動でbindが行われる } /** * Bootstrap any application services. * * @return void */ public function boot() { // } }終わりに
大きなメリットがあるわけでもなく、ちょっとしたtipsでした。
ただ、やはりフレームワークが用意してくれている方式に乗っかれると気持ちがいいですね。
- 投稿日:2020-02-16T20:36:57+09:00
マジックメソッドのPhpDocを自動生成する方法
はじめに
Laravelにはide-helper(php artisan ide-helper:models)というphpdocを自動生成してくれる便利なライブラリがありますが、ide-helperの対応範囲外のクラスにおいてもこれと同じようなことができないかということを考えてみました。
実現したこと
クラス内のプロパティに関するgetメソッドのphpdocを自動生成いたしました。
このことによりgetterメソッドを毎回書く必要がなくなり、getのマジックメソッドを基底クラスに一つ書いておくことでコード全体をすっきりとさせることができます。仕組み
PHPにはクラス情報を取得するReflectionClassという関数があります。
この関数を使うとなんと!PhpDocの情報やプロパティの情報も取得できたりします。
つまり既存PhpDocの内容に対し、プロパティのgetメソッドを追加することもできます。
※ide-helperでもこれと似たような手法でPhpDocの自動生成を行っていますサンプルコード
/** * Class UpdateGetterMethodPhpDoc */ class UpdateGetterMethodPhpDoc { /** * 指定ファイル内のPhpDocを更新する(プロパティのGetメソッドを追加) * * @param array $file_paths ファイルパス一覧 * @param string $filtering_class_name 対象となるクラス名 */ public function run(array $file_paths, string $filtering_class_name) { foreach ($file_paths as $file_path) { // 対象となるクラス以外は何もしない if (strpos($file_path->getRealPath(), $filtering_class_name) === false) { continue; } // ファイル名からクラスを生成し、該当クラス内のプロパティのGetメソッドをPhpDocとして定義する foreach (ClassMapGenerator::createMap($file_path->getRealPath()) as $model => $class_file_path) { $php_docs = []; $reflection = new ReflectionClass($model); if (empty($reflection->getDocComment())) { throw new LogicException('クラスのPhoDocが未定義です。必ず入力して下さい'); } foreach ($reflection->getProperties() as $property) { preg_match('/@var([^\n]*)/', $property->getDocComment(), $variable_data_list); $this->verifyProperty($reflection->getName(), $property, $variable_data_list); [ $data_type, $description, ] = explode(' ', ltrim($variable_data_list[1])); $php_docs[] = sprintf('%s %s() %s', $data_type, Str::camel($property->getName()), $description); } $blade_file = view('Component.PhpDoc.base', [ 'namespace' => $reflection->getNamespaceName(), 'class_name' => $reflection->getShortName(), 'php_docs' => $php_docs, ])->render(); $new_file = str_replace($reflection->getDocComment(), rtrim($blade_file), File::get($class_file_path)); File::delete($class_file_path); File::put($class_file_path, $new_file); } } } /** * プロパティが正しく定義されているかどうかの検証 * * @param string $class_name クラス名 * @param ReflectionProperty $property プロパティ情報 * @param string[] $variable_data_list プロパティーの@var部分を切り取った情報 [0:キーワード(@var)を含む文字列、1:マッチした部分のみの文字列] */ private function verifyProperty(string $class_name, ReflectionProperty $property, array $variable_data_list) { if (empty($property->getDocComment())) { throw new LogicException(sprintf('%sのプロパティである%sのPhoDocが未定義です。必ず入力して下さい', $class_name, $property->getName())); } if (empty($variable_data_list) || empty($variable_data_list[1])) { throw new LogicException(sprintf('%sのプロパティである%sのPhoDocが正しくありません。@var及び型を付けて下さい', $class_name, $property->getName())); } if (strpos($variable_data_list[1], 'mixed') !== false) { throw new LogicException(sprintf('%sのプロパティである%sのPhoDocが正しくありません。プロパティの型にmixedは使用しないで下さい', $class_name, $property->getName())); } } } /** * Class PhpDocCreateCommand */ class PhpDocCreateCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'php_doc_create {target_directory} {filtering_class_name}'; /** * The console command description. * * @var string */ protected $description = 'プロパティ用のGetメソッドのためのphpdocを生成する'; /** * プロパティ用のGetメソッドのためのphpdocを生成する */ public function handle() { $filtering_class_name = $this->argument('filtering_class_name'); $file_paths = File::allFiles(app_path($this->argument('target_directory'))); $update_getter_method_php_doc = new UpdateGetterMethodPhpDoc(); $update_getter_method_php_doc->run($file_paths, $filtering_class_name . '.php'); } }base.blade.php/** * Class {{ $class_name }} * * @package{{ sprintf(' %s',$namespace) }} @foreach($php_docs as $php_doc) * @@method {{ $php_doc }} @endforeach */
- 投稿日:2020-02-16T18:57:10+09:00
PhpDocが書かれているかどうかをチェックする方法
はじめに
PhpDoc皆さん書いてますか?
補完を最大限効かせるためにできれば全部書いていきたいですが、抜けているかどうかのチェックを目視で確認するのって面倒ですよね。
面倒なことは自動化しちゃいましょう!仕組み
PHPにはクラス情報を取得するReflectionClassという関数があります。
そして、この関数を使うとなんと!PhpDocの情報も取得できたりします。
つまり、書いてなければnullが返ってきます。
※補足すると各メソッドの行番号やプロパティの内容、publicかどうかなども取得できます。サンプルコード
/** * Class PhpDocCheckCommand */ class PhpDocCheckCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'php_doc_check {target_directory_path}'; /** * The console command description. * * @var string */ protected $description = 'phpdocの存在をチェックする'; /** * phpdocの存在をチェックする */ public function handle() { $target_directory_path = app_path($this->argument('target_directory_path')); $check_php_doc = new CheckPhpDoc(); $check_php_doc->run($target_directory_path); } } /** * Class CheckPhpDoc */ class CheckPhpDoc { /** * 指定ファイル内のPhpDocが正しく書かれているかどうかを検証する * * @param string $target_directory_path 対象のディレクトリのパス */ public function run(string $target_directory_path) { foreach (ClassMapGenerator::createMap($target_directory_path) as $model => $class_file_path) { $this->verifyPhpDoc($model); } } /** * クラスのPhpDocの検証 * * @param $model */ private function verifyPhpDoc($model) { $reflection = new ReflectionClass($model); // クラスのPhpDocの検証 if (empty($reflection->getDocComment())) { throw new LogicException(sprintf('%sクラスのPhoDocが未定義です。必ず入力して下さい', $reflection->getName())); } // クラス内のプロパティのPhpDocの検証 foreach ($reflection->getProperties() as $property) { if (empty($property->getDocComment())) { throw new LogicException(sprintf('%sのプロパティである%sのPhoDocが未定義です。必ず入力して下さい', $reflection->getName(), $property->getName())); } } // クラス内のメソッドのPhpDocの検証 foreach ($reflection->getMethods() as $method) { if (empty($method->getDocComment())) { throw new LogicException(sprintf('%sのメソッドである%sのPhoDocが未定義です。必ず入力して下さい', $reflection->getName(), $method->getName())); } } }
- 投稿日:2020-02-16T17:17:13+09:00
【Laravel 7 リリース】向け、Upgrade Guideの日本語訳
Laravel 7系
Laravel公式サイトにより、Laravel 7のリリースは2020年の3月3日と発表されました?
皆さんは6系にしましたか?7系もう目の前ですよ!?
ただし、7はLTS(Long-Term Support)じゃなさそうなので、商用なら6の方が良いかな。Laravel 6
- 2021年9月3日までのバグ修正
- 2022年9月3日までのセキュリティ修正
Laravel 7
- 2021年9月3日までのバグ修正
- 2022年9月3日までのセキュリティ修正
packagistのLaravel 7.0すでに
dev-develop
ブランチに更新したので、
以下のコマンドはblog7というLaravelアプリが作成できます。
composer create-project --prefer-dist laravel/laravel blog7 dev-develop
7系と遊びたい方はぜひ!!
変わっているものは、以下に記載されているようにそんなに多くありませんが、5.x系前半からなど、だんだんキツくなるでしょう。個人プロジェクトは早くアップデートしましょうね。では、早速見てみましょう?
Upgrade Guide
6.xから7へ
PHPバージョン
- 7.2.5 以上は必須
Symfony 5 関連のアップグレード
- 影響性 : 高
Laravel7 は Symfony5系のコンポネートを使用しているので、Symfony5系の変更によって、変更が必要になってきます。
App\Exceptions\Handler
クラスのreport
とrender
メソードはException
インスタンスを格納されなくて、インターフェイスThrowable
のインスタンスを格納します。// Laravel 6 public function report(Exception $exception); public function render($request, Exception $exception)⬇︎
// Laravel 7 use Throwable; public function report(Throwable $exception); public function render($request, Throwable $exception);コンフィグファイルの
session
のoption
のデフォルト値の変更// Laravel 6 'secure' => env('SESSION_SECURE_COOKIE', false). 'same_site' => null,⬇︎
// Laravel 7 'secure' => env('SESSION_SECURE_COOKIE', null), 'same_site' => 'lax',Authenticationー認証
- 影響性 : 高
全ての認証系のscaffoldingは
laravel/ui
に移動されました。もし5系のphp artisan make:auth
か、6系php artisan ui:auth
利用しているなら、laravel/ui
を~2.0
にする必要があります。composer require laravel/ui "~2.0"
Date Serializationー日付のシリアライズ化
- 影響性 : 高
Eloquentの
toArray
とtoJson
メソードを使う際、Laravel7は新たな日付のシリアライズフォーマットを使用します。Laravel7は日付のシリアライズをする時に、タイムゾン秒の小数部に対応しているISO-8601に適用されるCarbonのtoJson
メソードを使用します。プラス、この変更はより良いフロント側の日付の対応を提供します。7系前の日付フォーマット
2019-12-02 20:01:00
は7系から2019-12-02T20:01:00.283041Z
に更新されます。もし7系以前のフォーマットを使用したければ、モデルに
serializeDate
をoverrideしてください。/** * Prepare a date for array / JSON serialization. * * @param \DateTimeInterface $date * @return string */ protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); }この変更はモデルレベルの影響しかないです。データベースに保存されているデータに影響しません。
Blade
The component Method
- 影響性 : 中
Blade::component
メソードをBlade::aliasComponent
に変更したので、使用している場合は変更してください。Blade Components & "Blade X"
- 影響性 : 中
Laravel7 は公式的にBladeの"tag components"をサポートします。もし続いて
spatie/laravel-blade-x
パッケージ利用の場合は、Blade::withoutComponentTags
メソードを使って、Bladeの"tag components"を無効にしてください。
もしspatie/laravel-blade-x
パッケージ使用てなければ、これを無視してよろしいです。
使用している場合は、withoutComponentTags
メソードをAppServiceProvider
のboot
に追加してください。use Illuminate\Support\Facades\Blade; Blade::withoutComponentTags();Factory Types
- 影響性 : 中
7系から"factory types"機能を削除します。この機能は2016年の10月からドキュメントに下げられて、もし使っている場合はよりフレキシブルなfactory states機能に移行してください。
Eloquent
The addHidden / addVisible Methods
- 影響性 : 低
ドキュメントされていない
addHidden
とaddVisible
メソードが削除されました。使用している場合はmakeHidden
とmakeVisible
を使ってください。The booting / booted Methods
- 影響性 : 低
モデルの"boot"の時にロジックを追加するメソード
booting
とbooted
をEloquentに追加しました。もし同じ名前のメソードを使っている場合は名前を変更してください。Route Binding
- 影響性 : 低
Illuminate\Contracts\Routing\UrlRoutable
インターフェイスにあるresolveRouteBinding
メソードは$field
パラメータを使います。もしこのインターフェイスを使用していれば、更新してください。更に、
Illuminate\Database\Eloquent\Model
クラスのresolveRouteBinding
メソードも$field
パラメータを使いますので、もしこのメソードをoverrideしたら、更新してください。最後、
Illuminate\Http\Resources\DelegatesToResources
traitのresolveRouteBinding
メソードも$field
パラメータを使いますので、もしこのメソードをoverrideしたら、更新してください。The
getOriginal
Method
- 影響性 : 低
$model->getOriginal()
メソードはキャストされたモデールを参考にします。もし以前のキャストされない、生の属性を使用したい場合はgetRawOriginal
を使ってください。
TokenRepositoryInterface
クラス
- 影響性 : 低
Illuminate\Auth\Passwords\TokenRepositoryInterface
にrecentlyCreatedToken
メソードを追加したので、もしこのインターフェイスを使用している場合は、recentlyCreatedToken
メソードを追加してください。HTTPーPSR-7の適用性
- 影響性 : 低
PSR-7レスポンス生成ためのZend Diactorosライブラリが推奨されません。もしPSR-7の適用性のために、使用している場合は
nyholm/psr7
composerパッケージを使用してください。更に、composerパッケージのsymfony/psr-http-message-bridge ^2.0
も一緒にインストールしてください。MailーMarkdownメールテンプレートの更新
デフォルトのMarkdownメールテンプレートのデザインなどはより良くなります。プラス、ドキュメントに書かれていない
promotion
テンプレートは削除されます。Queueー非推奨される
--daemon
削除
- 影響性 : 低
queue:work
コマンドのフラグ--daemon
が削除されます。daemonとして実行されるのはデフォルトになります。Resourcesー
Illuminate\Http\Resources\Json\Resource
クラス
- 影響性 : 低
非推奨される
Illuminate\Http\Resources\Json\Resource
は削除されます。リソースはIlluminate\Http\Resources\Json\JsonResource
クラスを継承にします。Sessionー
array
セッションドライバ
- 影響性 : 低
array
セッションドライバのデータはカレントリクエストに持続的にアクセスできるようになります。7系以前は使えません。Testingー
assertSee
アサーション
- 影響性 : 中
TestResponse
クラスのassertSee
アサーションは自動的にエスケープされます。もし手動的にエスケープしてきたら、しないでください。Validationー
different
ルール
- 影響性 : 中
different
ルールはリクエストに特定のパラメータが足りない場合に通りません。
リソース:https://laravel.com/docs/master/upgrade
現在2020年2月16日です。新たな情報が出たら、更新したいと思います。
- 投稿日:2020-02-16T17:17:13+09:00
【Laravel 7 リリース】向け、 Laravel7のインストール方とUpgrade Guideの日本語訳
Laravel 7系
Laravel公式サイトにより、Laravel 7のリリースは2020年の3月3日と発表されました?
皆さんは6系にしましたか?7系もう目の前ですよ!?
ただし、7はLTS(Long-Term Support)じゃなさそうなので、商用なら6の方が良いかな。Laravel 6
- 2021年9月3日までのバグ修正
- 2022年9月3日までのセキュリティ修正
Laravel 7
- 2021年9月3日までのバグ修正
- 2022年9月3日までのセキュリティ修正
現時点Laravel 7のインストール方
packagistのLaravel 7.0すでに
dev-develop
ブランチに更新したので、
以下のコマンドはxyyoというLaravelアプリが作成できます。
composer create-project --prefer-dist laravel/laravel xyyo dev-develop
7系と遊びたい方はぜひ!!
変わっているものは、以下に記載されているようにそんなに多くありませんが、5.x系前半からなど、だんだんキツくなるでしょう。個人プロジェクトは早くアップデートしましょうね。では、早速見てみましょう?
Upgrade Guide
6.xから7へ
PHPバージョン
- 7.2.5 以上は必須
Symfony 5 関連のアップグレード
- 影響性 : 高
Laravel7 は Symfony5系のコンポネートを使用しているので、Symfony5系の変更によって、変更が必要になってきます。
App\Exceptions\Handler
クラスのreport
とrender
メソードはException
インスタンスを格納されなくて、インターフェイスThrowable
のインスタンスを格納します。// Laravel 6 public function report(Exception $exception); public function render($request, Exception $exception)⬇︎
// Laravel 7 use Throwable; public function report(Throwable $exception); public function render($request, Throwable $exception);コンフィグファイルの
session
のoption
のデフォルト値の変更// Laravel 6 'secure' => env('SESSION_SECURE_COOKIE', false). 'same_site' => null,⬇︎
// Laravel 7 'secure' => env('SESSION_SECURE_COOKIE', null), 'same_site' => 'lax',Authenticationー認証
- 影響性 : 高
全ての認証系のscaffoldingは
laravel/ui
に移動されました。もし5系のphp artisan make:auth
か、6系php artisan ui:auth
利用しているなら、laravel/ui
を~2.0
にする必要があります。composer require laravel/ui "~2.0"
ちなみに、scaffoldingのフロント側デフォルトは
vue
使用ですが、パラメータ指定でArguments:type ー The preset type (bootstrap, vue, react)
変更することもできます。Date Serializationー日付のシリアライズ化
- 影響性 : 高
Eloquentの
toArray
とtoJson
メソードを使う際、Laravel7は新たな日付のシリアライズフォーマットを使用します。Laravel7は日付のシリアライズをする時に、タイムゾン秒の小数部に対応しているISO-8601に適用されるCarbonのtoJson
メソードを使用します。プラス、この変更はより良いフロント側の日付の対応を提供します。7系前の日付フォーマット
2019-12-02 20:01:00
は7系から2019-12-02T20:01:00.283041Z
に更新されます。もし7系以前のフォーマットを使用したければ、モデルに
serializeDate
をoverrideしてください。/** * Prepare a date for array / JSON serialization. * * @param \DateTimeInterface $date * @return string */ protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); }この変更はモデルレベルの影響しかないです。データベースに保存されているデータに影響しません。
Blade
The component Method
- 影響性 : 中
Blade::component
メソードをBlade::aliasComponent
に変更したので、使用している場合は変更してください。Blade Components & "Blade X"
- 影響性 : 中
Laravel7 は公式的にBladeの"tag components"をサポートします。もし続いて
spatie/laravel-blade-x
パッケージ利用の場合は、Blade::withoutComponentTags
メソードを使って、Bladeの"tag components"を無効にしてください。
もしspatie/laravel-blade-x
パッケージ使用てなければ、これを無視してよろしいです。
使用している場合は、withoutComponentTags
メソードをAppServiceProvider
のboot
に追加してください。use Illuminate\Support\Facades\Blade; Blade::withoutComponentTags();Factory Types
- 影響性 : 中
7系から"factory types"機能を削除します。この機能は2016年の10月からドキュメントに下げられて、もし使っている場合はよりフレキシブルなfactory states機能に移行してください。
Eloquent
The addHidden / addVisible Methods
- 影響性 : 低
ドキュメントされていない
addHidden
とaddVisible
メソードが削除されました。使用している場合はmakeHidden
とmakeVisible
を使ってください。The booting / booted Methods
- 影響性 : 低
モデルの"boot"の時にロジックを追加するメソード
booting
とbooted
をEloquentに追加しました。もし同じ名前のメソードを使っている場合は名前を変更してください。Route Binding
- 影響性 : 低
Illuminate\Contracts\Routing\UrlRoutable
インターフェイスにあるresolveRouteBinding
メソードは$field
パラメータを使います。もしこのインターフェイスを使用していれば、更新してください。更に、
Illuminate\Database\Eloquent\Model
クラスのresolveRouteBinding
メソードも$field
パラメータを使いますので、もしこのメソードをoverrideしたら、更新してください。最後、
Illuminate\Http\Resources\DelegatesToResources
traitのresolveRouteBinding
メソードも$field
パラメータを使いますので、もしこのメソードをoverrideしたら、更新してください。The
getOriginal
Method
- 影響性 : 低
$model->getOriginal()
メソードはキャストされたモデールを参考にします。もし以前のキャストされない、生の属性を使用したい場合はgetRawOriginal
を使ってください。
TokenRepositoryInterface
クラス
- 影響性 : 低
Illuminate\Auth\Passwords\TokenRepositoryInterface
にrecentlyCreatedToken
メソードを追加したので、もしこのインターフェイスを使用している場合は、recentlyCreatedToken
メソードを追加してください。HTTPーPSR-7の適用性
- 影響性 : 低
PSR-7レスポンス生成ためのZend Diactorosライブラリが推奨されません。もしPSR-7の適用性のために、使用している場合は
nyholm/psr7
composerパッケージを使用してください。更に、composerパッケージのsymfony/psr-http-message-bridge ^2.0
も一緒にインストールしてください。MailーMarkdownメールテンプレートの更新
デフォルトのMarkdownメールテンプレートのデザインなどはより良くなります。プラス、ドキュメントに書かれていない
promotion
テンプレートは削除されます。Queueー非推奨される
--daemon
削除
- 影響性 : 低
queue:work
コマンドのフラグ--daemon
が削除されます。daemonとして実行されるのはデフォルトになります。Resourcesー
Illuminate\Http\Resources\Json\Resource
クラス
- 影響性 : 低
非推奨される
Illuminate\Http\Resources\Json\Resource
は削除されます。リソースはIlluminate\Http\Resources\Json\JsonResource
クラスを継承にします。Sessionー
array
セッションドライバ
- 影響性 : 低
array
セッションドライバのデータはカレントリクエストに持続的にアクセスできるようになります。7系以前は使えません。Testingー
assertSee
アサーション
- 影響性 : 中
TestResponse
クラスのassertSee
アサーションは自動的にエスケープされます。もし手動的にエスケープしてきたら、しないでください。Validationー
different
ルール
- 影響性 : 中
different
ルールはリクエストに特定のパラメータが足りない場合に通りません。
個人的に7系に非常に楽しみにしています?
特にこれ、元々はモデルにgetRouteKeyName
メソード使って、primary keyをoverrideしないといけないこと以下のように記述すれば、終わりみたい!便利そう!Route::get('/posts/{post:slug}', function (Post $post) { // ... });
リソース:
https://laravel.com/docs/master/upgrade
https://laravel-news.com/implicit-route-model-binding現在2020年2月16日の最新情報です。リリースノートなど新たな情報が出たら、更新したいと思います。
- 投稿日:2020-02-16T14:08:39+09:00
Laravel マイグレーションのエラー メモ
Laravel マイグレーション時にエラー起きたのでメモ
エラー
$php artisan migrate Base table or view already exists: 1050 Table 'hogehogeテーブル' already exists (SQL: rename table `hogeカラム` to `hugaカラム`)原因
カラムをリネームするマイグレーションファイルが実行される前に、既にリネームされてるのでエラーになってます。
私は最初このエラーが起きたとき、エラーが起きてるマイグレーションファイルに、カラムが既に変わってたらリネームを実行しないようにする処理を書き足そうとしてましたが、マイグレーションファイルは基本的に変更しません。
解決方法
DBのmigrationsテーブルにエラーが起きたマイグレーションファイルを挿入しました。
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (「id」, 'エラーが起きたマイグレーションファイル', 「数字」);migrationsテーブルに登録されたマイグレーションファイルはmigrateコマンドで実行されない為です。
上記の方法で無事マイグレーションできました。
- 投稿日:2020-02-16T11:05:12+09:00
laravelインストールからnginx起動してindex.phpを表示するまで
laravel環境構築
(1)Homebrewのインストール
1.こちらのリンクをコマンドラインでうつ。
2.バージョンを確認。$ brew -v Homebrew 2.2.5(2)composerのインストール
composerとは、PHPで使用するライブラリやパッケージを管理するツールのこと。
1.composeインストール
$ brew install composer2.バージョンを確認
$ composer -v ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.9.3 2020-02-04 12:58:49(3)laravelのインストール
1.laravelのインストーラをダウンロード
$ composer global require "laravel/installer"2.laravelがあるか確認
$ cd ~/.composer/vendor/bin $ ls laravel3.laravelコマンドを使えるようにする
$ export PATH="$PATH:/Users/<UserName>/.composer/vendor/bin"※には自分のmacのユーザー名を入力。
4.バージョンを確認
$ laravel -v Laravel Installer 2.3.0(4)laravelのディレクトリ作成
適当な所に作成。
$ cd ~/src/ $ laravel new laravel_sample※laravel new <ディレクトリ名>とすると必要なパッケージがすべて揃い、laravelの環境が整う。
(5)nginxのインストール
1.brewでインストール
$ brew install nginx2.バージョン確認
$ nginx -v nginx version: nginx/1.17.8(6)php-fpm(php72)をインストール
php-fpmとは、nginxでphpを動かす際に必要なサーバのこと。
$ brew install php72(7)nginx.confの設定を変更する
$ cd /usr/local/etc/nginx/ $ vi nginx.conf▼変更前
#location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}▼変更後
location ~ \.php$ { root /usr/local/var/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/var/www$fastcgi_script_name; include fastcgi_params; }nginxとphp-fpmの起動
nginxの起動 $ brew services start nginx phpの起動 $ brew services start php@7.2動作確認
以下のURLにアクセスする
http://127.0.0.1:8080/ここまででnginxの動作は確認できた!!!
次からはindex.phpを表示させていく。。。。nginx.configの設定変更
$ cd /usr/local/etc/nginx/ $ vi nginx.conf変更1
▼変更前
location / { root html; index index.html index.htm; }▼変更後
location / { root /usr/local/var/www/; index index.php index.html try_files $uri $uri/ /index.php; }変更2
▼変更前
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }▼変更後
location ~ \.php$ { root /usr/local/var/www/xxxx/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }nginxを再起動
$ brew services restart nginx動作確認
- 投稿日:2020-02-16T10:19:53+09:00
【Laravel】formで入力されたデータを保存しているstore メソッド
初めてのLARAVEL 5.6 : (16) FORMの作成で勉強中。
formで入力されたデータを保存しているstoreメソッドについてまとめてみる。以下のようなフォームがある。
create.blade.php<form method="POST" action="/articles" accept-charset="UTF-8"> @csrf <div class="form-group"> <label for="title">Title:</label> <input class="form-control" name="title" type="text" id="title"> </div> <div class="form-group"> <label for="body">Body:</label> <textarea class="form-control" name="body" cols="50" rows="10" id="body"></textarea> </div> <div class="form-group"> <label for="published_at">Publish On:</label> <input class="form-control" name="published_at" type="date" id="published_at"> </div> <div class="form-group"> <input class="btn btn-primary form-control" type="submit" value="Add Article"> </div> </form>以下のstoreメソッドは、
\Request::all()
でformからの入力を受け取り記事を作成している。ArticlesController.php... public function store() { $inputs = \Request::all(); Article::create($inputs); return redirect('articles'); }ちなみに、
dd($inputs);
の結果は、以下array:4 [▼ "_token" => "D1zCIbRcEzYrqracQtyPbDFuKcGHLHcm2aNddRig" "title" => "入力したタイトル" "body" => "入力した記事" "published_at" => "2018-08-27" ]以下のstoreメソッドは、メソッドの引数から
Illuminate\Http\Request クラスのインスタンス
を取得し、バリデーションを追加している。
メソッドの引数にタイプヒントでクラスを記述する方法である。
タイプヒンティングについては、PHPの型宣言(タイプヒンティング)がわかりやすい。ArticlesController.phppublic function store(Request $request) { $rules = [ 'title' => 'required|min:3', 'body' => 'required', 'published_at' => 'required|date' ]; $validated = $request->validate($rules); Article::create($validated); return redirect('articles'); }ちなみに、
dd($request);
の結果は、以下Illuminate\Http\Request {#51 ▼ #json: null #convertedFiles: null #userResolver: Closure($guard = null) {#31 ▶} #routeResolver: Closure() {#215 ▶} +attributes: Symfony\Component\HttpFoundation\ParameterBag {#53 ▶} +request: Symfony\Component\HttpFoundation\ParameterBag {#52 ▼ #parameters: array:4 [▼ "_token" => "FQjoGK4AbyJVCVmvaqWANu73Jpae5uq62fIHqW2h" "title" => "入力したタイトル" "body" => "入力した記事" "published_at" => "2018-08-27" ] } +query: Symfony\Component\HttpFoundation\ParameterBag {#59 ▶} +server: Symfony\Component\HttpFoundation\ServerBag {#55 ▶} +files: Symfony\Component\HttpFoundation\FileBag {#56 ▶} +cookies: Symfony\Component\HttpFoundation\ParameterBag {#54 ▶} +headers: Symfony\Component\HttpFoundation\HeaderBag {#57 ▶} #content: null #languages: null #charsets: null #encodings: null #acceptableContentTypes: null #pathInfo: "/articles" #requestUri: "/articles" #baseUrl: "" #basePath: null #method: "POST" #format: null #session: Illuminate\Session\Store {#234 ▶} #locale: null #defaultLocale: "en" -preferredFormat: null -isHostValid: true -isForwardedValid: true basePath: "" format: "html" }
Article::create(変数);
の変数は、配列でなければエラーが出るのだが、$validated = $request->validate($rules);
で、なぜ配列が作成できるのかはいまいち分からない。
- 投稿日:2020-02-16T02:13:29+09:00
【MacOS】やろうよLaravel環境設定
目的
LaravelをMacにインストールしたので、備忘録です。
完全初心者向けに書いているので、初めての方も是非参考にしてみてください。この記事で出来ること
- Laravel、Composer、PHPをインストールすることが出来ます。
- Laravelを使ってプロジェクトを作成出来ます。
- Laravelで作ったプロジェクトをWEBブラウザで表示出来ます。
使用する環境
MacOS 10.15.2
Laravel 6.15.1
PHP 7.3.14環境構築編
Homebrewをインストールしよう
ターミナルに指定のコマンドを流し、(念のため)下記のコマンドを流してください。
brew updatePHPを入れてみよう
brew install php@7.3ポイント
・phpはusr/local/etc/php/7.3/以下に設定ファイル入る
・念のためバージョン確認してみましょう。php -vComposerを入れてみよう
Get Started
=>Downloading the Composer Executable
=>Globally
=>the Download page instructions
下記URLに記載されているコマンドを順に実行します。(一個ずつ!)https://getcomposer.org/download/
usr/local以下に配置してあげましょう。(コマンドラインから使えるようにします。)
mv composer.phar /usr/local/bin/composerLaravelを入れてみよう
Laravelをインストール。
https://readouble.com/laravel/4.2/ja/quick.html※ここらへんで詰まることあるので、参考記事
https://qiita.com/Shogo1992/items/6b6609087f97bff717c7composer global require laravel/installer環境変数に追加
ホームディレクトリに移動してください。cd ~環境変数を設定するファイル(.bash_profile)があるか確認し、変数追加してください。
vi .bash_profile(
e
を入力するとEdit出来ます。終わったらesc押して:q
で離脱)
これを追加export PATH="$HOME/.composer/vendor/bin:$PATH"変数を有効化しましょう。
source .bash_profileプロジェクト作成編
プロジェクトを作成してみよう
プロジェクト名を決めてプロジェクトを作成しよう。
※プロジェクトとは
Laravelの標準セットが備わった一つのフォルダを作成することです。
ここにLaravelで必要なソースコードがインストールされています。composer create-project laravel/laravel 【プロジェクト名】作成されるフォルダ説明
- app(処理を記述)
- config(各種設定ファイル)
- database(データベース設定)
- public(ファビコンなど)
- resources(view)
- storage(データを保存)
- tests(ユニットテスト)
- vendor(外部のライブラリを格納)
サーバーを起動してみよう
php artisan servelocalhost:8000にブラウザからアクセスしてみよう。
無事Laravelのロゴ画面が表示されたら完了です。お疲れ様でした。
- 投稿日:2020-02-16T01:02:42+09:00
Laravel +Vagrant + CentOS7.5環境でphp artisan migrate時のエラー『could not find driver』の解決方法
php artisan migrate実行時にエラー
could not find driver、ドライバーがないよと怒られる。
経緯としては、Homesteadでの環境構築の利用ではないLaravel環境構築後にて(CentOS利用)Todoアプリを作成中php artisan migrate実行時に以下のエラー出現
$ php artisan migrate Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE') at /vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 PDOException::("could not find driver") /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 Please use the argument -v to see more details.環境情報
name version CentOS 7.5.1804 Vagrant 2.2.6 VirtualBox 6.0.16 Laravel 6.12.0 PHP 7.4 Windows 10 ※2020/02/16時点
原因
PHPのモジュールにmysqlのドライバ(php-mysqlnd)が入っていなかった。
私の凡ミスだがPHPモジュールにmysqlのドライバを入れ忘れていた。
解決策
1.モジュール確認
PHPにmysqlのドライバがいるか確認
pdo_mysqlがいればOK$ php -m | grep pdo pdo_sqlitesqlite用のドライバしかいない
2.php-mysqlndをインストール
yum installにて phpのmysqlドライバ、『php-mysqlnd』をインストール
※remiリポジトリ使っていたのでremiもインストール$ sudo yum -y install --enablerepo=remi,remi-php74 php-mysqlnd Loaded plugins: fastestmirror ~~~~~~~以下省略~~~~~~~3.確認
$ php -m | grep pdo pdo_mysql pdo_sqlite確認できたのでApacheを再起動
$ sudo service httpd restartartisanコマンド実行
$ php artisan migrate Migration table created successfully. Migrating: 2020_02_15_150504_create_posts_table Migrated: 2020_02_15_150504_create_posts_table (0 seconds)解決
結論
mysqlをインストール時、phpのmysqlモジュールのインストールも忘れずに
参考サイト
- 投稿日:2020-02-16T01:02:42+09:00
Laravel +Vagrant + CentOS環境でphp artisan migrate時のcould not find driverエラーの解決方法
事象
could not find driver、ドライバーがないよと怒られる。
経緯としては、Homesteadでの環境構築の利用ではないLaravel環境構築後にて(CentOS利用)Todoアプリを作成中php artisan migrate実行時に以下のエラー出現
$ php artisan migrate Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE') at /vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 PDOException::("could not find driver") /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 Please use the argument -v to see more details.環境情報
name version CentOS 7.5.1804 Vagrant 2.2.6 VirtualBox 6.0.16 Laravel 6.12.0 PHP 7.4 Windows 10 ※2020/02/16時点
原因
PHPのモジュールにMySQLのドライバ(php-mysqlnd)が入っていなかった。
私の凡ミスだがPHPモジュールにMySQLのドライバを入れ忘れていた。
解決策
1.モジュール確認
PHPにMySQLのドライバがいるか確認
pdo_mysqlがいればOK$ php -m | grep pdo pdo_sqlitesqlite用のドライバしかいない
2.php-mysqlndをインストール
yum installにて PHPのMySQLドライバ、『php-mysqlnd』をインストール
※remiリポジトリ使っていたのでremiもインストール$ sudo yum -y install --enablerepo=remi,remi-php74 php-mysqlnd Loaded plugins: fastestmirror ~~~~~~~以下省略~~~~~~~3.確認
$ php -m | grep pdo pdo_mysql pdo_sqlite確認できたのでApacheを再起動
$ sudo service httpd restartartisanコマンド実行
$ php artisan migrate Migration table created successfully. Migrating: 2020_02_15_150504_create_posts_table Migrated: 2020_02_15_150504_create_posts_table (0 seconds)解決
結論
MySQLをインストール時、PHPのMySQLモジュールのインストールも忘れずに
参考サイト
- 投稿日:2020-02-16T00:25:27+09:00
Laravel artisanコマンド逆引き
Laravelでは、アプリ開発に便利な数多くのコマンド・Artisanが用意されています。これらのコマンドを活かすことで、より労力を少なく効率的な開発が可能となります。
コマンド一覧を確認する
php artisan listどのrouteが設定されているか確認する
php artisan route:list対話型のコンソールtinkerの起動
php artisan tinkerマイグレーションファイルとテーブルの作成
php artisan make:migration create_shops_table --create=shopsマイグレーションの実行
php artisan migrateモデルクラスファイルのひな形作成
php artisan make:model <モデル名>コントローラークラスファイルのひな形作成
php artisan make:controller <コントローラー名>リクエストクラスのひな形作成
php artisan make:request <リクエストクラス名>シーダー用ファイルの作成
php artisan make:seeder <シーダークラス名>シーディングの実行
php artisan db:seedテーブルを全削除して、再作成
php artisan migrate:freshテーブルを全削除して、再作成、シーディングまで実行
php artisan migrate:refresh --seed