PHP code example of yeab / laravel-api-contract

1. Go to this page and download the library: Download yeab/laravel-api-contract library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yeab / laravel-api-contract example snippets


// routes/api.php
Route::post('/users', [UserController::class, 'store'])->name('users.store');

// app/Http/Controllers/UserController.php
public function store(StoreUserRequest $request)
{
    $user = User::create($request->validated());
    return new UserResource($user);
}

// app/Http/Requests/StoreUserRequest.php
public function rules()
{
    return [
        'name' => ['
bash
php artisan vendor:publish --provider="Yab\LaravelApiContract\Providers\LaravelApiContractServiceProvider" --tag="config"
bash
php artisan api-contract:build
bash
# Generate Swagger Docs
php artisan api-contract:swagger --path=public/swagger.json

# Generate TypeScript Interfaces
php artisan api-contract:typescript --output=resources/ts/types/api.ts

# Generate an API Client
php artisan api-contract:client --output=resources/ts/services/

# Scaffold PHPUnit Tests
php artisan api-contract:tests --output=tests/Feature/Api/