以上一章节的人员信息录入的功能为例,使用快速CURD命令是如何快速实现改功能的。

一、创建人员信息表

php artisan make:migration CreateMyStaffTable
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMyStaffTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('my_staff', function (Blueprint $table) {
            $table->id();
            $table->string('name')->default('')->comment('姓名');
            $table->tinyInteger('age')->default('1')->comment('年龄');
            $table->tinyInteger('height', false, true)->default('0')->comment('身高');
            $table->tinyInteger('weight')->default('0')->comment('体重');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('my_staff');
    }
}

二、快速CURD命令

执行命令

php artisan make:curd my_staff(表名) System(模块名) --lang(多语言可选)

参数1:数据表名称

参数2:功能所属的模块名称

参数3:多语言选项

该命令新增/修改的文件如下:

模型:Modules/System/Models/StaffModel.php
请求类:Modules/System/Http/Requests/StaffRequest.php
控制器:Modules/System/Http/Controllers/Admin/StaffController.php

列表模板:Modules/System/Resources/views/admin/staff/index.blade.php
新建模板:Modules/System/Resources/views/admin/staff/create.blade.php
编辑模板:Modules/System/Resources/views/admin/staff/edit.blade.php

路由:Modules/System/Routes/web.php
Javascript:public/mycms/admin/js/system.staff.js

 

三、添加权限节点说明

在 config/role.php 中添加以下代码后,再进行角色授权

'system.staff' => '人员管理',
'system/staff' => '人员列表',
'system/staff/create' => '新增人员',
'system/staff/edit' => '人员修改',
'system/staff/destroy' => '删除人员',

四、添加功能到菜单

至此,通用的人员信息录入功能就完成了。