Rest Api CRUD in Laravel with Api Resources

执行:

php artisan make:model Task –mf

批注 2020-04-14 030417

执行:

php artisan make:controller TaskController -r

批注 2020-04-14 030434

<?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');
    }
}

CreateTasksTable.php

执行:

php artisan migrate

猜你喜欢

转载自www.cnblogs.com/dzkjz/p/12695458.html