質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

解決済

1回答

914閲覧

Laravelのマイグレーション

ibu

総合スコア4

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2020/05/26 16:06

php artisan make:migration create_tasks_table --create=tasks
php artisan make:migration create_tasks_table
この2つの違いはなんなのでしょうか?
作成されたファイルを見比べてもわかりません。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ちょっと気になったのでlaravelのソースを追いかけました

MigrateMakeCommand.php(抜粋)

php

1 /** 2 * Execute the console command. 3 * 4 * @return void 5 */ 6 public function handle() 7 { 8 // It's possible for the developer to specify the tables to modify in this 9 // schema operation. The developer may also specify if this table needs 10 // to be freshly created so we can create the appropriate migrations. 11 $name = Str::snake(trim($this->input->getArgument('name'))); 12 13 $table = $this->input->getOption('table'); 14 15 $create = $this->input->getOption('create') ?: false; 16 17 // If no table was given as an option but a create option is given then we 18 // will use the "create" option as the table name. This allows the devs 19 // to pass a table name into this option as a short-cut for creating. 20 if (! $table && is_string($create)) { 21 $table = $create; 22 23 $create = true; 24 } 25 26 // Next, we will attempt to guess the table name if this the migration has 27 // "create" in the name. This will allow us to provide a convenient way 28 // of creating migrations that create new tables for the application. 29 if (! $table) { 30 [$table, $create] = TableGuesser::guess($name); 31 } 32 33 // Now we are ready to write the migration out to disk. Once we've written 34 // the migration out, we will dump-autoload for the entire framework to 35 // make sure that the migrations are registered by the class loaders. 36 $this->writeMigration($name, $table, $create); 37 38 $this->composer->dumpAutoloads(); 39 }

--create=tasksがあったら

php

1 if (! $table && is_string($create)) { 2 $table = $create; 3 4 $create = true; 5 }

ここの処理で$tabletasksが、$cratetrueが入る


--create=tasksがなかったら

php

1 if (! $table) { 2 [$table, $create] = TableGuesser::guess($name); 3 }

ここに行く($namecreate_tasks_table)

TableGuesser.php

php

1<?php 2 3namespace Illuminate\Database\Console\Migrations; 4 5class TableGuesser 6{ 7 const CREATE_PATTERNS = [ 8 '/^create_(\w+)_table$/', 9 '/^create_(\w+)$/', 10 ]; 11 12 const CHANGE_PATTERNS = [ 13 '/_(to|from|in)_(\w+)_table$/', 14 '/_(to|from|in)_(\w+)$/', 15 ]; 16 17 /** 18 * Attempt to guess the table name and "creation" status of the given migration. 19 * 20 * @param string $migration 21 * @return array 22 */ 23 public static function guess($migration) 24 { 25 foreach (self::CREATE_PATTERNS as $pattern) { 26 if (preg_match($pattern, $migration, $matches)) { 27 return [$matches[1], $create = true]; 28 } 29 } 30 31 foreach (self::CHANGE_PATTERNS as $pattern) { 32 if (preg_match($pattern, $migration, $matches)) { 33 return [$matches[2], $create = false]; 34 } 35 } 36 } 37}

self::CREATE_PATTERNSに引っかかるので
return [$matches[1], $create = true];
により戻り値が['tasks', true]になる

よって全く同じになる。

投稿2020/05/26 17:00

rururu3

総合スコア5545

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ibu

2020/05/27 07:07

ありがとうございます! 本当に一緒だったのですね笑 今まで適当にオプション付けていたのですがスッキリしました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問