Laravel without frontend
I've recently started working on a new project where Laravel is used as a backend API only.
It was always possible to use Laravel without frontend scaffolding, but it recently became a bit more complicated, especially with the new artisan dev command.
Delete the frontend scaffolding
So when you create a new Laravel project, it comes with some frontend scaffolding. You can remove it by deleting the following files and folders:
.npmrcpackage.jsonresources/js/app.jsresources/views/welcome.blade.phpvite.config.js
This is if you used the Blade frontend scaffolding. If you used another preset, you might have to delete additional files.
Remove the web routes
This step is optional. By default Laravel ships with a routes/web.php file where you reference your routes by default. This goes through the web middleware and is useful when you serve a frontend (sessions, validations etc..).
In my case I'll only deal with API routes so I can safely remove this file.
When it's done, you must remove it from the routing configuration.
If you want to setup the api you can do so with artisan install:api
Disable vite from the artisan dev command
By default artisan dev will try to run vite to compile the frontend assets. Since we don't have any frontend scaffolding, we need to disable this behavior.
Now your app is cleaned from any frontend and you can start working on your API.