首页 > Windows开发 > 详细

Rest Api CRUD in Laravel with Api Resources

时间:2020-04-14 09:11:16      阅读:67      评论:0      收藏:0      [点我收藏+]

执行:

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

CreateTasksTable.php

执行:

php artisan migrate

Rest Api CRUD in Laravel with Api Resources

原文:https://www.cnblogs.com/dzkjz/p/12695458.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!