Day 1
I have some experience with Laravel (I built spendweek.com with Laravel and Vue). But it’s been a while since I dove into the ecosystem.
I have to say, it’s a lot. You are presented with a lot of options right up front:
- Blade
- Livewire
- Inertia
- Breeze
- Jetstream
I got a bit of analysis paralysis because I didn’t want to start in the wrong direction. Luckily, I have this project and the clock is ticking. Having a React frontend already built narrowed down the options. Breeze seemd to fit my needs and the constraints of having a React frontend already. Also, this reference implementation gave me confidence I’d have documentation to follow if I got stuck.
Step 1: Install Laravel Installer
composer global require laravel/installer
Step 2: Create a new Laravel project
Troubleshooting
laravel: command not found
I tried running laravel new friendlyfriends
, but it failed with the following error: laravel: command not found
. Composer was not in my path, so I added this line to my .bashrc
file: export PATH="~/.config/composer/vendor/bin:$PATH"
. Then I ran source ~/.bashrc
to apply the change. (See https://stackoverflow.com/a/27915343)
Troubleshooting
The following PHP extensions are required but are not installed: mbstring
sudo apt install php8.3-mbstring
Creating the project
After that, I followed the steps here: https://github.com/laravel/breeze-next?tab=readme-ov-file#installation
laravel new ff-laravel --database=pgsql
cd ff-laravel
composer require laravel/breeze --dev
php artisan breeze:install api
php artisan migrate
Troubleshooting
PDOException Could not find driver
I did not have PHP’s pgsql extension installed.
sudo apt install php8.3-pgsql
Step 3: Test run
I ultimately want to run this in a docker container through Sail, but I also wanted to test it out right away. These were the commands printed in the terminal after running laravel new ff-laravel --database=pgsql
:
npm install && npm run build
composer run dev
I was able to see the web app running at http://localhost:8000. It had an error because postgres is not running.
Step 4: Run Sail
See https://laravel.com/docs/11.x/sail#installing-sail-into-existing-applications
composer require laravel/sail --dev
php artisan sail:install # (selecting pgsql when asked which services to install)
./vendor/bin/sail up
./vendor/bin/sail artisan migrate
I was able to see the web app running at http://0.0.0.0:80.
Troubleshooting:
Why is a mysql container running when I do sail up
?
I think I accidentally had mysql as one of the options when I ran php artisan sail:install
. I didn’t realize it was a checkbox situation. I removed the mysql service from the docker-compose.yml
file and ran:
docker compose down -v
./vendor/bin/sail build --no-cache
./vendor/bin/sail up
I don’t know if all of that was necessary, but it fixed the issue.
Next steps
- See what I can do with the API
- Add the React frontend to the project
- See https://github.com/laravel/breeze-next for integrating frontend and API
Conclusion
From start to finish, that took about 2-2.5hours to work through including reading docs and troubleshooting issues (and writing this blog post). I’ll be interested to see how this compares to other frameworks.