When I create an api and use laravel resources, is it better to get the full data and then choose which columns to send in the resource file, or maybe when selecting data from the database, determine which columns should be selected?
1)
return UserResource::collection(User::all());
// Resource file:
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name
];
}
return UserResource::collection(User::all('id', 'name'));
// Resource file:
public function toArray($request)
{
return parent::toArray($request);
}