PHP code example of devlabor / laravel-api

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

    

devlabor / laravel-api example snippets


use DevLabor\Api\Http\Controllers\ApiController;

// ...

class ProductApiController extends ApiController
{
// ...
}

// ...

Route::resource('products', 'Api\ProductApiController');

use DevLabor\Api\Http\Resources\ApiResource;

class Product extends ApiResource
{
//
}

return [
	'pagination' => [
		/**
		 * Number of items per page returned in index()
		 */
		'items' => 20
	]
];

// ...

protected $authorizeAbilities = [
	'viewAny', // index
	'view', // show
	'store',
	'update',
	'destroy'
];

protected $authorizeAbilities = false;

    /**
     * Models location
     * @var string
     */
    protected $modelPath = 'App\\Models\\';

    /**
     * Resources location
     * @var string
     */
    protected $resourcePath = 'App\\Http\\Resources\\';
bash
php artisan vendor:publish --tag=api