1 year ago

Is there any route alignment/indentation pattern? (and more questions)

Posted 1 year ago by Leandro_Haruki

Hello guys, i would like to know some nice way to set up my routes, since i have started learning Laravel my routes always felt really messy and unaligned.

This is how my routes usually look:

Route::post('password/reset', 'Auth\[email protected]')->name('password.reset');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::post('signup', 'Auth\[email protected]')->name('signup');

Since i'm still new to the framework, i've been changing my routes time to time due to namespaces, Model bindings instead of putting it in the Request body, etc. So i thought about aligning routes like:

Route::post('password/reset',   'Auth\[email protected]')                 ->name('password.reset');
Route::post('password/email',   'Auth\[email protected]')   ->name('password.email');
Route::post('signup',           'Auth\[email protected]')                       ->name('signup');

I think that aligning the routes parameters would make the routes look better, however, i'm afraid it will be a pain to keep everything aligned.

I would like to know how you guys manage routes:

  • Should i separate my api routes in different route files?
  • Is this alignment thing bad?
  • Should i follow a single pattern of using only Route::resource, separate every request type or mix it when needed?
  • I usually set a middleware to groups only and put it in controllers constructors to single routes, is it bad for code maintenance? (is there a better way?)

TL;DR: I'm a Laravel noob and my api routes file look ugly and long.

EDIT: Added questions & title change.

Please sign in or create an account to participate in this conversation.