laravel 在voyager中定义额外路线时出现问题

oxcyiej7  于 2023-02-25  发布在  其他
关注(0)|答案(1)|浏览(112)

我在我的laravel应用程序中使用voyager包。我用{lang}前缀做了一个路由组用于本地化。在基础应用程序中一切正常,但是当我转到voyager面板的路由/admin时,它返回一个错误,说我缺少一个参数。
在我自己的应用程序的路线中,我只是这样做:

Route::group(['prefix' => '{lang}'], function () {
   //code...
});

然而,voyager的routes文件相当复杂,有几个嵌套的组。我尝试在许多不同的行添加前缀,但没有得到任何结果。如果有人能告诉我在哪里以及如何在这个route文件中添加{lang}前缀,我将非常感激。
这是voyager在vendor\tcg\voyager\routes\voyager.php中的路径文件:

<?PHP

use Illuminate\Support\Str;
use TCG\Voyager\Events\Routing;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Events\RoutingAdmin;
use TCG\Voyager\Events\RoutingAfter;
use Illuminate\Support\Facades\Route;
use TCG\Voyager\Events\RoutingAdminAfter;

/*
|--------------------------------------------------------------------------
| Voyager Routes
|--------------------------------------------------------------------------
|
| This file is where you may override any of the routes that are included
| with Voyager.
|
*/

Route::group(['as' => 'voyager.'], function () {
event(new Routing());

$namespacePrefix = '\\' . config('voyager.controllers.namespace') . '\\';

Route::get('login', ['uses' => $namespacePrefix . 'VoyagerAuthController@login',     'as' => 'login']);
Route::post('login', ['uses' => $namespacePrefix . 'VoyagerAuthController@postLogin', 'as' => 'postlogin']);

Route::group(['middleware' => 'admin.user'], function () use ($namespacePrefix) {
    event(new RoutingAdmin());

    // Main Admin and Logout Route
    Route::get('/', ['uses' => $namespacePrefix . 'VoyagerController@index',   'as' => 'dashboard']);
    Route::post('logout', ['uses' => $namespacePrefix . 'VoyagerController@logout',  'as' => 'logout']);
    Route::post('upload', ['uses' => $namespacePrefix . 'VoyagerController@upload',  'as' => 'upload']);

    Route::get('profile', ['uses' => $namespacePrefix . 'VoyagerUserController@profile', 'as' => 'profile']);

    try {
        foreach (Voyager::model('DataType')::all() as $dataType) {
            $breadController = $dataType->controller
                ? Str::start($dataType->controller, '\\')
                : $namespacePrefix . 'VoyagerBaseController';

            Route::get($dataType->slug . '/order', $breadController . '@order')->name($dataType->slug . '.order');
            Route::post($dataType->slug . '/action', $breadController . '@action')->name($dataType->slug . '.action');
            Route::post($dataType->slug . '/order', $breadController . '@update_order')->name($dataType->slug . '.update_order');
            Route::get($dataType->slug . '/{id}/restore', $breadController . '@restore')->name($dataType->slug . '.restore');
            Route::get($dataType->slug . '/relation', $breadController . '@relation')->name($dataType->slug . '.relation');
            Route::post($dataType->slug . '/remove', $breadController . '@remove_media')->name($dataType->slug . '.media.remove');
            Route::resource($dataType->slug, $breadController, ['parameters' => [$dataType->slug => 'id']]);
        }
    } catch (\InvalidArgumentException $e) {
        throw new \InvalidArgumentException("Custom routes hasn't been configured because: " . $e->getMessage(), 1);
    } catch (\Exception $e) {
        // do nothing, might just be because table not yet migrated.
    }

    // Menu Routes
    Route::group([
        'as'     => 'menus.',
        'prefix' => 'menus/{menu}',
    ], function () use ($namespacePrefix) {
        Route::get('builder', ['uses' => $namespacePrefix . 'VoyagerMenuController@builder',    'as' => 'builder']);
        Route::post('order', ['uses' => $namespacePrefix . 'VoyagerMenuController@order_item', 'as' => 'order_item']);

        Route::group([
            'as'     => 'item.',
            'prefix' => 'item',
        ], function () use ($namespacePrefix) {
            Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerMenuController@delete_menu', 'as' => 'destroy']);
            Route::post('/', ['uses' => $namespacePrefix . 'VoyagerMenuController@add_item',    'as' => 'add']);
            Route::put('/', ['uses' => $namespacePrefix . 'VoyagerMenuController@update_item', 'as' => 'update']);
        });
    });

    // Settings
    Route::group([
        'as'     => 'settings.',
        'prefix' => 'settings',
    ], function () use ($namespacePrefix) {
        Route::get('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController@index',        'as' => 'index']);
        Route::post('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController@store',        'as' => 'store']);
        Route::put('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController@update',       'as' => 'update']);
        Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerSettingsController@delete',       'as' => 'delete']);
        Route::get('{id}/move_up', ['uses' => $namespacePrefix . 'VoyagerSettingsController@move_up',      'as' => 'move_up']);
        Route::get('{id}/move_down', ['uses' => $namespacePrefix . 'VoyagerSettingsController@move_down',    'as' => 'move_down']);
        Route::put('{id}/delete_value', ['uses' => $namespacePrefix . 'VoyagerSettingsController@delete_value', 'as' => 'delete_value']);
    });

    // Admin Media
    Route::group([
        'as'     => 'media.',
        'prefix' => 'media',
    ], function () use ($namespacePrefix) {
        Route::get('/', ['uses' => $namespacePrefix . 'VoyagerMediaController@index',              'as' => 'index']);
        Route::post('files', ['uses' => $namespacePrefix . 'VoyagerMediaController@files',              'as' => 'files']);
        Route::post('new_folder', ['uses' => $namespacePrefix . 'VoyagerMediaController@new_folder',         'as' => 'new_folder']);
        Route::post('delete_file_folder', ['uses' => $namespacePrefix . 'VoyagerMediaController@delete', 'as' => 'delete']);
        Route::post('move_file', ['uses' => $namespacePrefix . 'VoyagerMediaController@move',          'as' => 'move']);
        Route::post('rename_file', ['uses' => $namespacePrefix . 'VoyagerMediaController@rename',        'as' => 'rename']);
        Route::post('upload', ['uses' => $namespacePrefix . 'VoyagerMediaController@upload',             'as' => 'upload']);
        Route::post('crop', ['uses' => $namespacePrefix . 'VoyagerMediaController@crop',             'as' => 'crop']);
    });

    // BREAD Routes
    Route::group([
        'as'     => 'bread.',
        'prefix' => 'bread',
    ], function () use ($namespacePrefix) {
        Route::get('/', ['uses' => $namespacePrefix . 'VoyagerBreadController@index',              'as' => 'index']);
        Route::get('{table}/create', ['uses' => $namespacePrefix . 'VoyagerBreadController@create',     'as' => 'create']);
        Route::post('/', ['uses' => $namespacePrefix . 'VoyagerBreadController@store',   'as' => 'store']);
        Route::get('{table}/edit', ['uses' => $namespacePrefix . 'VoyagerBreadController@edit', 'as' => 'edit']);
        Route::put('{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController@update',  'as' => 'update']);
        Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController@destroy',  'as' => 'delete']);
        Route::post('relationship', ['uses' => $namespacePrefix . 'VoyagerBreadController@addRelationship',  'as' => 'relationship']);
        Route::get('delete_relationship/{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController@deleteRelationship',  'as' => 'delete_relationship']);
    });

    // Database Routes
    Route::resource('database', $namespacePrefix . 'VoyagerDatabaseController');

    // Compass Routes
    Route::group([
        'as'     => 'compass.',
        'prefix' => 'compass',
    ], function () use ($namespacePrefix) {
        Route::get('/', ['uses' => $namespacePrefix . 'VoyagerCompassController@index',  'as' => 'index']);
        Route::post('/', ['uses' => $namespacePrefix . 'VoyagerCompassController@index',  'as' => 'post']);
    });

    event(new RoutingAdminAfter());
});

//Asset Routes
Route::get('voyager-assets', ['uses' => $namespacePrefix . 'VoyagerController@assets', 'as' => 'voyager_assets']);

event(new RoutingAfter());
});
pod7payv

pod7payv1#

我找不到任何方法使voyager路线与本地化一起工作。所以我将voyager路线移到前缀为{lang}的路线组之外。
如果你正在做这确保你到vendor\tcg\voyager\routes\voyager.php并且改变所有'/'路由到'/dashboard'.dashboard是可互换的与任何短语你想要的.

相关问题