Laravel Integration
This document will help you set up the Laravel framework on a Windows machine and further the development process that includes REST APIs.
Step 1: Installation
Download the WAMP server and install it
Once WAMP is installed, expose the PHP path in the system environment variable
Right click This PC-> Properties-> Advance System Settings (Under System->About)-> Advanced-> Envrionment Variables-> click Path-> and add as new path C:\wamp64\bin\php\php8.2.13
Visit the Composer website and download the Composer-Setup.exe
Verify the installation by typing composer in your terminal.
Create a Laravel Project
Open your terminal and navigate to the directory where you want to install Laravel.
Run the following Composer command to create a new Laravel project:
composer create-project --prefer-dist laravel/laravel piappstudio
Navigate to piappstudio and execute this command
php artisan serve
Create a Models
Create customer & invoice models by using the below comments
php artisan make:model Customer --all
php artisan make:model Invoice --all
Create a relationship between Customers & Invoices
Customer to Invoice has 1:N relationship. Update the Customer model by adding the below function in app/Models
class Customer extends Model
{
use HasFactory;
public function invoices() {
return $this->hasMany(Invoice::class);
}
}
Invoice to Custom has N:1 relationship
class Invoice extends Model
{
use HasFactory;
public function customer() {
return $this->BelongsTo(Customer::class);
}
}
Update the table structure of both in database/migrations/
Update factories files to generate dummy values when seeds are executed
Update seeders files to create dummy data for customers
Open .env file change the database configurations to point mysql
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=piappstudio
DB_USERNAME=root
DB_PASSWORD=******
Add this line in boot() function to avoid mysql server errors in app/Provider/AppServiceProvider
Schema::defaultStringLength(191);Finally, execute
php artisan migrate:fresh --seed
To Add Route Service provider
php artisan make:Provider RouteServiceProvider
To integrate sanctum:
composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"