Route and Submission Agreements

I'm looking for information on naming conventions that I use to route names and view directory structures.

Let's say I have the following routes:

Route::get('/teams/choose', ' ChooseTeamController@index ')->name('teams.choose.index'); Route::post('/teams/choose', ' ChooseTeamController@choose ')->name('teams.choose'); Route::get('/teams/{team}/manage', ' ManageTeamController@index ')->name('teams.team.manage.index'); 

For get routes, I would by default put views in the directory structure corresponding to the name of the route. For instance. resources/views/teams/team/manage/index.blade.php . However, I feel that is too much.

I feel this will be confusing everywhere (for me and other developers) if I used a view directory structure like this and not the last example: resources/views/team/manage/index.blade.php - the plural of team not used, therefore, when I have other views, for example (using the original example): resources/views/teams/choose.index they are not visually related. That is, they have another "root" directory - teams vs team .

Any input or advice would be appreciated.

+6
source share
1 answer

For get routes, I usually put the views in the directory structure corresponding to the name of the route. For instance. resources/views/teams/team/manage/index.blade.php . However, I think this is too verbose.

I agree.


From the Laravel Docs :

Laravel uses the typical RESTful CRUD approach when assigning resource routes to a controller. Each verb (i.e. GET, POST, PUT, DELETE) receives a designated URI , an action (technically, a controller method) and a route name (sometimes, /path/to/blade/view ).

So from your snippet:

 // return view(teams.index) Route::get('/teams', ' TeamController@index '); // return view(teams.create) Route::get('/teams/create', ' TeamsController@create '); // redirect('/home'); Route::post('/teams', ' TeamController@store '); // return view('teams.profile') Route::get('/teams/profile', ' TeamController@profile ')->name('profile'); 

I use this resource table to remind me what to do and what to do not all the time.

Perhaps checking out some of the great Laravel codebases might help. In addition, the prospect of how other teams do things is always priceless.

I found that they are very useful:


Update

The key must adhere to standard CRUD actions, i.e. index, display, create, save, edit, update and delete. Looks will fall right in their place.

Check out Adam Watan speaks at Laracon EU , demonstrating how CRUDDY can be with a little imagination.

+8
source

Source: https://habr.com/ru/post/1013684/


All Articles