When I made this repository years ago, other tools were in their infancy and I applied the practices I deemed to make the most sense back then to this boilerplate.
Since then, many new tools have come out and have changed the way I think about creating new projects.
If I were to create a project consisting of an API based back-end and a front-end today, I would do so this way:
One repository for front-end using NextJS
No Redux if at all possible, rely on react-query or SWR to handle state coming from the server, and use context if something is needed on a global level.
Another Laravel repository for the back-end
Use Sanctum for authorization with your SPA front-end, possibly use Laravel Fortify for your logic set-up or roll your own.
This is the boilerplate that I personally use for getting projects off the ground quickly using my favourite stack of technologies. It uses Laravel as a backend API service, and has a React single page application in the front end.
I personally use Vagrant and Homestead, so these installation instructions assume that you use Homestead as well, but the project's dependencies are very similar to the base Laravel installation, so if you use something else to develop locally, the instructions shouldn't change too much.
git clone https://github.com/huwcarwyn/react-laravel-boilerplate
composer install
php artisan key:generate
php artisan migrate
php artisan passport:install
and php artisan storage:link
npm install
php artisan migrate
Since this application takes advantage of webpack hashes to bust caches in production, the asset() and mix() helpers are used when loading front end assets. This means that it is important to set a correct value for ASSET_URL
in your .env
file. Otherwise Laravel will load assets from the wrong place.
If you are developing using npm run hot
- make sure to set ASSET_URL
to http://localhost:9000
, otherwise for development set it to the root URL of your app.
In production you will need to set this value to the public root, that will usually be the same as your domain name.