adrema/app/Group/Actions/GroupIndexAction.php

34 lines
726 B
PHP
Raw Permalink Normal View History

2023-12-30 02:02:07 +01:00
<?php
namespace App\Group\Actions;
use App\Group;
use App\Group\Resources\GroupResource;
use Illuminate\Database\Eloquent\Collection;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class GroupIndexAction
{
use AsAction;
/**
* @return Collection<int, Group>
*/
public function handle(): Collection
{
return Group::get();
}
public function asController(): Response
{
2023-12-30 22:21:08 +01:00
session()->put('menu', 'group');
session()->put('title', 'Gruppierungen');
2023-12-30 02:02:07 +01:00
return Inertia::render('group/Index', [
2023-12-30 22:21:08 +01:00
'data' => GroupResource::collection(Group::where('parent_id', null)->withCount('children')->get()),
2023-12-30 02:02:07 +01:00
]);
}
}