PHP code example of sinclairt / api-foundation

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

    

sinclairt / api-foundation example snippets


Route::group(['middleware' => 'api', 'namespace' => 'Api'], function()
{
    Route::get('api/v1/user/{user}/restore', [
        'as'   => 'api.v1.user.restore',
        'uses' => 'UserController@restore'
    ]);
    
    Route::post('api/v1/user/{user}/filter', [
        'as'   => 'api.v1.user.filter',
        'uses' => 'UserController@filter'
    ]);
    
    Route::resource('/api/v1/user', 'UserController', ['except' => ['create', 'edit']]);
}):

protected $bindings = [
    'user'
];

public function boot( Router $router )
{
    foreach ( $this->bindings as $model )
    {
        $router->bind(strtolower($model), function ( $value ) use ( $model )
        {
            $model = app(studly_case($model));

            $model = in_array(SoftDeletes::class, class_uses($model)) ? $model->withTrashed()
                                                                              ->find($value) : $model->find($value);

            // the abort is optional
            if ( is_null($model) )
                abort(403);

            return $model;
        });
    }

    parent::boot($router);
}