React.js is one of the most popular front-end frameworks, but it lacks examples of how to integrate it with Laravel API. So, in this long article, I will show you how to do it in details, step-by-step.
Install Laravel and Laravel Breeze
We start from the very beginning, by installing a fresh Laravel project, and a Laravel Breeze starter kit:
laravel new project cd project // editing .env file here composer install php artisan migrate composer require laravel/breeze php artisan breeze:install blade
By this point, we should have a default Laravel Breeze with Tailwind CSS design, and Login/Register functionality:
Creating Model and API CRUD
We will manage one table called Companies, with four text fields: name, email, address, website.
So, we create the model, and automatically create migrations with -m:
php artisan make:model Company -m
This is the DB structure: database/migrations/xxxxx_create_companies_table.php:
return new class extends Migration { public function up() { Schema::create('companies', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email'); $table->string('address')->nullable(); $table->string('website')->nullable(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('companies'); } };
Then, of course, we run...