Rest Api CRUD in Laravel with Api Resources

执行:

php artisan make:model Task –mf

Rest Api CRUD in Laravel with Api Resources

执行:

php artisan make:controller TaskController -r

Rest Api CRUD in Laravel with Api Resources

Rest Api CRUD in Laravel with Api Resources
<?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

Rest Api CRUD in Laravel with Api Resources

上一篇:easyui datagrid的API


下一篇:easyui datagrid的列编辑