Route::get('/', function () {//get路由return view('admin.order',['name'=>'试图路由']);//resources/views/admin/order模板,传递一个name键});Route::get('/user',[UserController::class,'index']);//UserController控制器类,下面的index方法Route::get('/shop',shopController::class);//如果是单行为控制器,不需要传方法名Route::post('/user', function () {//POST路由return '用户接口';});Route::match(['get','post'], '/getpost',function () {//多种路由接口支持return '支持多种接口方式';});Route::any('/any', function () {//POST路由return '所有类型路由';});Route::redirect('/aa', '/',301);//域名重定向,默认302,适合老版本的路由跳转到新版本的路由Route::view('/view','welcome');//视图路由,参数1:路由、参数2:模板,调用resources\views下面的模板Route::get('/get/{id}', function ($data=null) {//POST路由return $data;});Route::get('/where/{id}', function ($data=null) {return $data;})->where('id','[0-9a-zA-Z]+');//路由正则限制Route::get('/wherearr/{id}/{re}', function ($data=null,$re=null) {return $data.$re;})->where(['id'=>'[0-9]+','re'=>'[a-zA-Z]+']);//路由正则多个限制Route::get('/mber/{id}', function ($data=null) {dd(route('mber.show',['id'=>$data]));//route查看路由的名字,参数1:路由名字、参数2:路由传参。})->name('mber.show');//给当前路由命名Route::get('/red/{id}', function ($re) {return redirect()->route('mber.show',['id'=>$re]);//路由跳转});Route::name('admin.')->prefix('admin')->group(function (){//路由组,相当于admin/orderRoute::get('/order',function (){return 'adminorer';});Route::get('/list',function (){return 'list列表';});});Route::name('user.')->//路由名称前缀domain('api.php.test')->//路由组的限制,不是api开始的域名不允许访问。prefix('user')->group(function (){//Route::get('/order',function (){return 'adminorer';});Route::get('/list',function (){return 'list列表';});});//资源路由1Route::resource('/shop',shopController::class)->only(['index','create']);//资源路由,only限制只需要路由类型//资源路由2Route::resource('/shop',shopController::class)->except(['upate','destroy']);//资源路由,except限制排除不需要路由类型//资源路由3Route::apiResource('/shop',shopController::class);//资源路由apiResource自动排除create和edit,创建和编辑都交给前端来做了,所以不需要。//资源路由4Route::resource('/shop',shopController::class)->names(['create'=>'shop.build']);//传入names数组来覆盖路由组的名称/*** 路由资源对应的方式* /shop对应index 对应列表 请求方式:GET* /shop/create 对应create创建 请求方式:GET* /shop/store 对应store 请求方式:POST* /shop/show 对应show 请求方式:GET* /shop/edit 对应edit编辑 请求方式:GET* /shop/{id} 对应更新 请求方式:PUT/PATCH* /shop/{id} 对应destroy删除 请求方式:DELETE*/
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号