如何在动态路由中添加Laravel前缀admin和user?

时间:2019-08-01 10:09:02

标签: laravel-5 routing

我创建了这样的路线。 如何在这样的动态路由中分隔前缀admin和user角色? 我很困惑

在此网络路由中,我需要使用中间件auth zizaco委托来分隔管理员和用户角色。 我怎样才能做到这一点? 有人知道吗?

<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/    
Route::get('{controller_name}',
        function ($controller_name, $query = null) {
            $function_name = 'index';
            $app = app();
            $controller = $app->make('\App\Http\Controllers\\' . ucfirst($controller_name) . 'Controller');
            return $controller->callAction($function_name, $parameters = [
                'param1' => $query
            ]);
        })->name('menu');

Route::get('{controller_name}/{function_name}/{query?}',
    function ($controller_name, $function_name, $query = null) {
        $app = app();
        $controller = $app->make('\App\Http\Controllers\\' . ucfirst($controller_name) . 'Controller');
        return $controller->callAction($function_name, $parameters = [
            'param1' => $query
        ]);
    })->name('menu');

Route::post('{controller_name}/{function_name}/{query?}',
    function ($controller_name, $function_name, $query = null) {
        $app = app();
        $controller = $app->make('\App\Http\Controllers\\' . ucfirst($controller_name) . 'Controller');
        return $controller->callAction($function_name, $parameters = [
            'param1' => $query
        ]);
    })->name('action-post');

0 个答案:

没有答案