PHP code example of nikserg / laravel-api-model

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

    

nikserg / laravel-api-model example snippets

 
return [
    ...
    'connections' => [
        ...
        'api_fruits' => [
            'driver'  => 'api',
            'baseUri' => env('API_FRUITS_HOST', 'https://fruits.com/v1'),
            'verify'  => false,
        ],
    ...
    ],
    ...
];

use nikserg\LaravelApiModel\ApiModel;
class Banana extends ApiModel
{
    protected $connection = 'api_fruits';
    protected $table = 'bananas';
}
 
'api_fruits' => [
    'driver'       => 'api',
    'baseUri'      => 'baseUri' => env('API_FRUITS_HOST', 'https://fruits.com/v1'),
    'verify'       => false,
    'configurator' => \App\Models\GuzzleConfigurator::class,
],
 
class GuzzleConfigurator implements \nikserg\LaravelApiModel\GuzzleConfigurator
{
    public static function modifyConfig(array $config): array
    {
        $user = auth()->user();
        $config['headers'] = [
            'Authorization' => 'Bearer ' . $user->getJwtToken(),
        ];
        return $config;
    }
}