Rest Api CRUD in Laravel with Api Resources
阿新 • • 發佈:2020-04-14
執行:
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(‘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