Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gitwithravish's avatar

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', '.*');
0 likes
4 replies
Sinnbeck's avatar

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

gitwithravish's avatar

Yes definitely, what you said is something about keeping things organised, but what I am asking is, is it okay to not have api and its own authentication system and put everything, both vue routes and ajax routes under laravel's auth middleware? I mean I don't see a big difference here but just wanted to put it out to see if there is anything that I am not aware of. @sinnbeck

Sinnbeck's avatar

I do that in a few project. I use ldap for auth so it just makes sense to use the default auth middleware (with some additions). I use react for the frontend, and have some some logic to check the user is signed in. Works great

tykus's avatar
tykus
Best Answer
Level 104

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.

2 likes

Please or to participate in this conversation.