执行:
php artisan make:model Task –mf
执行:
php artisan make:controller TaskController -r
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateTasksTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(‘tasks‘, function (Blueprint $table) { $table->id(); $table->unsignedBigInteger(‘user_id‘); $table->string(‘title‘); $table->text(‘description‘); $table->dateTime(‘due‘); $table->timestamps(); }); Schema::table(‘tasks‘, function (Blueprint $table) { $table->foreign(‘user_id‘)->references(‘id‘)->on(‘users‘)->cascadeOnDelete(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists(‘tasks‘); } }
执行:
php artisan migrate