PHP code example of dwivedianuj9118 / laravel-api-starter

1. Go to this page and download the library: Download dwivedianuj9118/laravel-api-starter 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/ */

    

dwivedianuj9118 / laravel-api-starter example snippets


'guards' => [

    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'jwt' => [
        'driver' => 'jwt',
        'provider' => 'users',
    ],

],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],
],


use Dwivedianuj9118\ApiStarter\Exceptions\ApiExceptionHandler;

->withExceptions(function (Exceptions $exceptions): void {
    $exceptions->render(function (Throwable $e, $request) {
        if ($request->is('api/*')) {
            return ApiExceptionHandler::handle($e);
        }
    });
});


use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Http\Request;

public function boot(): void
{
    RateLimiter::for('api', function (Request $request) {
        return Limit::perMinute(
            config('api-starter.rate_limit.per_minute')
        )->by($request->ip());
    });
}

use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use HasApiTokens;

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims(): array
    {
        return [];
    }
}

'annotations' => [
    base_path('app'),
    base_path('vendor/dwivedianuj9118/laravel-api-starter/src'),
],

'securityDefinitions' => [
    'securitySchemes' => [

        // JWT Authentication
        'bearerAuth' => [
            'type' => 'http',
            'scheme' => 'bearer',
            'bearerFormat' => 'JWT',
            'description' => 'JWT Authorization header using the Bearer scheme. Example: Bearer {token}',
        ],

        // Sanctum Authentication
        'sanctum' => [
            'type' => 'http',
            'scheme' => 'bearer',
            'description' => 'Sanctum token using Bearer scheme. Example: Bearer {token}',
            'in' => 'header',
        ],
    ],
],


bash
php artisan api-starter:install
bash
php artisan l5-swagger:generate