Multiple Cards
Is your feature request related to a problem? Please describe. This is more of a call for help than a feature request.
I read the documentation and looked through the issues but I can't seem to understand how to access query data or display multiple cards in layout().
I have a card presenter on my Service model and I'm trying to display a card collection. Basically display a card for every Service record on the Screen.
Describe the solution you'd like
It would be nice if I just could pass an array of Cardable elements and have them displayed.
public function query(): array
{
return [
'services' => Service::all()->presenter(),
];
}
public function layout(): array
{
return [
new Card('services', [
Link::make('Edit')->route('platform.service.edit', 'service.id'),
]),
];
}
Would this even work?
Describe alternatives you've considered
This is my current working version, is there a better way to do this?
public function query(): array
{
$this->services = Service::all();
$out = [];
foreach ($this->services as $service)
{
$out[$service->name] = $service->presenter();
}
return $out;
}
public function layout(): array
{
$cards = [];
foreach ($this->services as $service)
{
$cards[$service->name] = new Card($service->name, [
Link::make('Edit')->route('platform.service.edit', $service->id)
]);
}
return $cards;
}
Additional context I'm having a hard time understanding how to add layout elements dynamically.
@Davy1992 did you maybe manage to solve this issue some other way?