I prefer to add a third routes file ajax.php, if I ever want my api and ajax routes to be seperate (unless using inertia). Keeps the clutter to a minimum
Laravel + vue : Is it a bad practice to use web routes instead of api routes ?
For a Laravel + vue concept, usually vue handles the rendering and routing and laravel handles the api part. Is this a bad practice to simply do this instead of creating api routes and making a separate authentication for that?
web.php
/*
* Routes that laravel should handle
* These routes are create communication between vue components and database
*/
Route::get('products','ProductsController@index');
Route:;post('products','ProductsController@')
/*
* All other routes should be handed over to vue router
*/
Route::get('/{any}', 'SpaController@index')->where('any', '.*');
If you are using your API only with your own frontend, i.e. not third party apps, mobile apps etc, then token-based authentication (default for api routes) is a complication that you do not need to introduce; your session-based web authentication is perfectly acceptable. _It is your application, so you could add web middleware to the api routes to get the same end result, and some logical separation between the AJAX and non-AJAX routes is beneficial.
Please or to participate in this conversation.