How to write a URL to access controllers in different namespaces of Laravel?
怪我咯
怪我咯 2017-05-16 16:54:18
0
1
388

The following is an example from the documentation:

Route::group(['namespace' => 'Admin'], function(){
    // 控制器在 "App\Http\Controllers\Admin" 命名空间下

    Route::group(['namespace' => 'User'], function()
    {
        // 控制器在 "App\Http\Controllers\Admin\User" 命名空间下
    });
});

Assume that there is an ArticleController under both the Admin and User namespaces. To access these two different controllers, how should the URL be written?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
我想大声告诉你
Route::controller('/XX/api/' , "Admin\User\XXController");
Route::controller('/XX/api/' , "Admin\User");

Just follow the form Admin改为AdminUser即可
如果User是一个目录的话,写成AdminUserXXController as shown above

For example:

Route::group(['namespace' => 'Admin'], function(){
    // 控制器在 "App\Http\Controllers\Admin" 命名空间下

    Route::group(['namespace' => 'Amind\User'], function()
    {
        // 控制器在 "App\Http\Controllers\Admin\User" 命名空间下
    });
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template