PHP code example of nailfor / shazam-api

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

    

nailfor / shazam-api example snippets


    'providers' => [
        ...
        nailfor\shazam\API\Providers\RouteServiceProvider::class,
    ];




use nailfor\shazam\Http\Controllers\Controller;
use nailfor\shazam\API\Models\Paginator;

return [
    'namespace' => 'App',
    'path' => 'Http/Controllers',
    'routes' => [
        //there is subdirectory of Http/Controllers for routing
        'API',
    ],
    'paginator' => Paginator::class,
    'pages' => [
        'perPage' => 'per_page',
        'page' => 'page',
    ],

    'debug' => env('SQL_DEBUG', false),
];



namespace App\Repositories\API;

use App\Models\User;
use nailfor\shazam\API\Repositories\APIRepository;

class UserRepository extends APIRepository
{
    protected static string $model = User::class;
}



namespace App\Http\Controllers\API;

use App\Repositories\API\UserRepository;
use nailfor\shazam\API\Http\Controllers\ApiController;

class UserController extends ApiController
{
    public function __construct(UserRepository $model)
    {
        parent::__construct($model);
    }
}

class UserController extends ApiController
{
    //By default can't store and destroy
    protected array $can = [
        'store',
    ];

    //By default can index and show
    protected array $cant = [
        'index',
        'show',
    ];
    ...
}



namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'id' => '

class UserController extends ApiController
{
    protected static array $requests = [
        'store' => StoreRequest::class,
    ];
    ...
}

    \nailfor\shazam\API\Http\Middleware\RequestValidator::class,