1、首选声明一个资源路由
//资源路由里加“as”,可以表示上一级文件夹名称
Route::resource('role','RoleController',['as'=>'admin']);
查看资源路由列表
php artisan route:list
查看如图:
2、声明资源控制器
//-r 资源控制器 -m 指定参数转化的模型
php artisan make:controller Admin/RoleController -r -m Models/Role
查看资源控制器,如下所示:
<?php
namespace App\Http\Controllers\Admin;
use App\Models\Role;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class RoleController extends Controller {
/**
* 角色列表
*/
public function index() {
}
/**
* Show the form for creating a new resource.
* 添加界面展示
* @return \Illuminate\Http\Response
*/
public function create() {
//
}
/**
* Store a newly created resource in storage.
* 添加操作
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
//
}
/**
* Display the specified resource.
* 展示一条数据
* @param \App\Models\Role $role
* @return \Illuminate\Http\Response
*/
public function show(Role $role) {
}
/**
* Show the form for editing the specified resource.
* 更新页面展示
* @param \App\Models\Role $role
* @return \Illuminate\Http\Response
*/
public function edit(Role $role) {
//
}
/**
* Update the specified resource in storage.
* 更新操作
* @param \Illuminate\Http\Request $request
* @param \App\Models\Role $role
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Role $role) {
//
}
/**
* Remove the specified resource from storage.
* 删除操作
* @param \App\Models\Role $role
* @return \Illuminate\Http\Response
*/
public function destroy(Role $role) {
//
}
}