search

Home  >  Q&A  >  body text

How to write a URL to access controllers in different namespaces of Laravel?

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?

怪我咯怪我咯2789 days ago420

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:56:18

    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" 命名空间下
        });
    });
    

    reply
    0
  • Cancelreply