PHP code example of mkd / laravel-fast-api

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

    

mkd / laravel-fast-api example snippets


use MKD\FastAPI\Attributes\FastAPI;
use MKD\FastAPI\Attributes\FastAPIGroup;

#[FastAPIGroup(prefix: '/items', options: ['name' => 'items'], middlewares: ['auth'])]
class ItemsController extends Controller
{
    #[FastAPI(method: FastApiMethod::GET, path: '/data/{id}', options: ['functions' => [
        'whereIn' => ['id', ['2']],
    ], 'name' => 'item_id'])]
    public function getItem($id)
    {
        return response()->json(['item' => $id]);
    }
}

enum FastApiMethod
{
    case GET;
    case POST;
    case PUT;
    case PATCH;
    case OPTION;
    case DELETE;
    case ANY;
    case REDIRECT;
    case MATCH;
}

private array $supportedFunctions = [
    'middleware',
    'where',
    'whereNumber',
    'whereAlpha',
    'whereAlphaNumeric',
    'whereUuid',
    'whereUlid',
    'whereIn',
    'name',
    'withTrashed',
    'scopeBindings',
    'withoutScopedBindings',
];

return [
    //Paths to check for controllers that use fast-api
    'paths' => [
        app_path('Http/Controllers'),
    ],

    //Specify controllers that are not 
bash
  php artisan fast-api:cache
  
bash
  php artisan fast-api:clear-cache
  
bash
php artisan route:cache