Model
class Entity extends Model
{
...
}
EntityResource (the goal is to set theese resource fields dynamically)
public function toArray($request)
{
$fields = Field::byClassName(Entity::class)->get();
foreach ($fields as $item) {
$resource[$item->name] = data_get($this->resource, $item->name);
}
return $resource;
}
But, when I receive by this way resource collection, I have too many queries to db
$fields = Field::byClassName(Entity::class)->get();
as many as have resource items.
So, that would be good, if I set variable $fields (this collection is just some mapping of data) inside my controller and after pass it to resource collection method, some like this:
$fields = Field::byClassName(Entity::class)->get();
$entities = EntityResource::collection(Entity::all(), $fields); //doesn't work
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire