I have an API resource called FilmResource
, I've appended a new attribute to the model called is_new
and I've added this new attribute to the resource file, the issue is I have two endpoints that make use of this API resource and it's returning the attribute for both but I only want it returned for one method, is there a way you can specify certain keys to be returned in a response? if I use makeVisible
it makes no difference because it's only going from the API resource.
FilmController
This is the method I want it returning for, I've another method which is similar but I don't want it returned for that.
public function show(string $id)
{
$film = Film::findOrFail($id);
return new FilmResource($film);
}
FilmResource
public function toArray($request)
{
return [
'id' => $this->id,
'description' => $this->description,
'name' => $this->name,
'is_new' => $this->is_new
}
Does API resources override what attributes you set within your hidden/visible arrays?
Can you specify you want to hide a key from API resource when you return it in your controller?