PHP code example of swisnl / json-api-server

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

    

swisnl / json-api-server example snippets


   return [
     // Generator configuration
     'path' => [
         'model' => app_path('/'),
 
         'model_permissions' => app_path('Permissions/'),
 
         'translation' => app_path('Translations/'),
 
         'controller' => app_path('Http/Controllers/Api/'),
 
         'repository' => app_path('Repositories/'),
 
         'policy' => app_path('Policies/'),
 
         'auth_test' => base_path('tests/Authentication/'),
 
         'templates' => 'vendor/swisnl/laravel-api/resources/templates/',
 
         'routes' => app_path('Http/Routes/')
     ],
 
     'namespace' => [
         'model' => 'App',
 
         'model_permissions' => 'App\Permissions',
 
         'controller' => 'App\Http\Controllers\Api',
 
         'repository' => 'App\Repositories',
 
         'translation' => 'App\Translations',
 
         'policy' => 'App\Policies',
 
         'auth_test' => 'App\Tests\Authentication'
     ],
 
     // Permissions configuration
     'permissions' => [
         'checkDefaultIndexPermission' => false,
 
         'checkDefaultShowPermission' => false,
 
         'checkDefaultCreatePermission' => false,
 
         'checkDefaultUpdatePermission' => false,
 
         'checkDefaultDeletePermission' => false,
     ],
 
     // Load all relationships to have response exactly like json api. This slows down the API immensely.
     'loadAllJsonApiRelationships' => true,
]; 

return $this->respondWithOk($object);
return $this->respondWithPartialContent($object);
return $this->respondWithCreated($object);
return $this->respondWithNoContent($object);
return $this->respondWithCollection($object);

 protected $policies = [
     Sample::class => SamplePolicy::class,
 ];
 
 public function boot()
 {
     $this->registerPolicies();
 }    

$this->authorizeAction('show');

$this->authorizeAction('show', $requestedObject);
bash
$ php artisan json-api-server:generate-all {Model}
bash
$ php artisan json-api-server:generate-controller {name}
$ php artisan json-api-server:generate-model {name}
$ php artisan json-api-server:generate-model-permissions {name}
$ php artisan json-api-server:generate-policy {name}
$ php artisan json-api-server:generate-repository {name}
$ php artisan json-api-server:generate-routes {name}
$ php artisan json-api-server:generate-test {name}
$ php artisan json-api-server:generate-translation {name}
bash
$ php artisan vendor:publish --tag=laravel-api
$ php artisan vendor:publish --tag=laravel-api-templates
bash
$ composer migrate
$ php artisan passport:install