1. 程式人生 > WINDOWS開發 >Rest Api CRUD in Laravel with Api Resources

Rest Api CRUD in Laravel with Api Resources

執行:

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‘); } }
CreateTasksTable.php

執行:

php artisan migrate