Laravel Controller Subfolder routing

后端 未结 14 1559
一生所求
一生所求 2020-11-29 16:44

I\'m new to Laravel. To try and keep my app organized I would like to put my controllers into subfolders of the controller folder.

controllers\\
---- folder1         


        
14条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 17:35

    If you're using Laravel 5.3 or above, there's no need to get into so much of complexity like other answers have said. Just use default artisan command to generate a new controller. For eg, if I want to create a User controller in User folder. I would type

    php artisan make:controller User/User
    

    In routes,

    Route::get('/dashboard', 'User\User@dashboard');
    

    doing just this would be fine and now on localhost/dashboard is where the page resides.

    Hope this helps.

提交回复
热议问题