最近Laravelを始めました。
下記はartisanコマンドで生成されたファイルです。
パッと見、テーブル名はpostsでカラム名idはインクリメントで、カラム名が見当たらないが恐らくタイムスタンプで作成日のようなテーブル構造をcreateしてるんだなってのはわかるんですが、具体的にSchema::createの中が見てみたいです。
で、そのSchema::createですが
use Illuminate\Support\Facades\Schema;
ってなってるので作成したプロジェクト内を見ているのですが、それらしきものはありません。
どこで定義されているのでしょうか?
あと
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
とありますが、これはSchemaクラスのcreateメソッドの第一引数にpostsを、第二引数に
function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
}
というメソッドを使っているように見えるのですが、第二引数に渡しているメソッドのリターン(リターンがあるかどうかはわからないけど、そもそも第二引数に渡しているぐらいだから何かしらのリターンがあると思う)によって、createメソッドが動いているのでしょうか?
プログラムの繋がりがわからないです。
php
1<?php 2 3use Illuminate\Support\Facades\Schema; 4use Illuminate\Database\Schema\Blueprint; 5use Illuminate\Database\Migrations\Migration; 6 7class CreatePostsTable extends Migration 8{ 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('posts', function (Blueprint $table) { 17 $table->increments('id'); 18 $table->timestamps(); 19 }); 20 } 21 22 /** 23 * Reverse the migrations. 24 * 25 * @return void 26 */ 27 public function down() 28 { 29 Schema::dropIfExists('posts'); 30 } 31}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。