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/ */
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' => '