Why i am keep getting this error: Property [id] does not exist on this collection instance.
My method:
public function modes()
{
$modes = Genre::limit($this->limit)->get();
return new GenresResource($modes);
}
My Resource
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name
];
}
M Model
class Genre extends Model {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'genres';
protected $guarded = ['id'];
}
You'll want to change your controller method to indicate that it's receiving a collection, not a single model.
$modes = Genre::limit($this->limit)->get();
return GenresResource::collect($modes);
Generally you'll want to give your resource a singular name so you may want to consider calling it GenreResource
too.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments