I'm trying to use {JSON:API} with my Laravel app, and I can retrieve a list of records, but cannot access a single record.
I strictly followed the JSON:API tutorial (https://howtojsonapi.com/laravel.html), and I managed to run it and get the index list.
I used artisan to create all needed files : Adapter, Schema and Validator.
json-api-v1.php :
'resources' => [ 'titre' => App\Models\TitreModel::class, ];
api.php :
JsonApi::register('v1')->routes(function ($api, $router) {
$api->resource('titre');
});
TitreSchema.php :
class TitreSchema extends SchemaProvider
{
protected $resourceType = 'titre';
public function getId($resource)
{
}
public function getAttributes($resource)
{
return [
'ID' => $resource->ID,
'ID_DICO' => $resource->ID_DICO,
];
TitreAdapter.php :
class TitreAdapter extends AbstractAdapter
{
protected $attributes = [
'ID' => 'ID',
'ID_DICO' => 'ID_DICO',
];
protected $relationships = [];
protected $primaryKey = 'ID';
public function __construct(StandardStrategy $paging)
{
parent::__construct(new TitreModel(), $paging);
}
TitreController.php :
class TitreController extends BaseController
{
public function index()
{
return new TitreCollection(TitreModel::paginate(parent::handlePerPage()));
}
public function show(TitreModel $titre)
{
return new TitreResource($titre);
}
When I visit /api/v1/titre, it's ok, I can get the json:api formatted records list.
But when I visit /api/v1/titre/1, I get this error :
"messages":{"count":1,"messages":[{"message":"[15:37:22] LOG.error: Argument 1 passed to Illuminate\\Routing\\Middleware\\ThrottleRequests::addHeaders() must be an instance of Symfony\\Component\\HttpFoundation\\Response, null given, called in C:\\www\\AppFlx\\dev\\dk_api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\ThrottleRequests.php on line 62
I'm the first to use JSON:API in my enterprise, so none of my colleagues can help me.
I only followed the tutorial, added nothing, changed nothing, and I don't use headers, so I don't get where it comes from.