Open noweh opened 4 days ago
@noweh Thanks for your report.
There is an error in the following documentation. You need in your CatProvider
to return the DTO ApiResource/Cat.php
and not the model Models/Animal.php
.
However, if you still want to do this you need to add the $fillable property to your Dto, like this:
<?php
namespace App\Models;
use ApiPlatform\Metadata\ApiResource;
use Illuminate\Database\Eloquent\Model;
#[ApiResource]
class Animal extends Model
{
protected $fillable = ['id', 'name', 'age'];
}
This PR https://github.com/api-platform/docs/pull/2036 will solve the issue in the documentation
API Platform version(s) affected: api-platform/laravel 4.0.3
Description
When attempting to use Data Transfer Objects (DTOs) with Laravel, as described in the documentation, I encounter a 404 error on the newly added route:
How to reproduce
api-platform.php
to include the DTO resource path:CatProvider
class that fetches data from the model:Expected Behavior The
GET /cats/{id}
route should return the correct data for theCat
resource using the CatProvider.