adrema/app/Activity/Actions/IndexAction.php

37 lines
1.1 KiB
PHP
Raw Normal View History

2023-02-14 14:27:11 +01:00
<?php
namespace App\Activity\Actions;
use App\Activity;
use App\Activity\Resources\ActivityResource;
2023-02-23 22:43:13 +01:00
use App\Http\Views\ActivityFilterScope;
2023-02-14 14:27:11 +01:00
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class IndexAction
{
use AsAction;
2023-02-23 22:43:13 +01:00
public function handle(ActivityFilterScope $filter): AnonymousResourceCollection
2023-02-14 14:27:11 +01:00
{
2023-02-23 22:43:13 +01:00
return ActivityResource::collection(Activity::local()->withFilter($filter)->paginate(20));
2023-02-14 14:27:11 +01:00
}
public function asController(ActionRequest $request): Response
{
2023-02-25 17:19:17 +01:00
session()->put('menu', 'activity');
session()->put('title', 'Tätigkeiten');
2023-02-23 22:43:13 +01:00
$filter = ActivityFilterScope::fromRequest($request->input('filter'));
return Inertia::render('activity/VIndex', [
'data' => $this->handle($filter),
2023-02-25 18:00:23 +01:00
'toolbar' => [
['href' => route('activity.create'), 'label' => 'Tätigkeit erstellen', 'color' => 'primary', 'icon' => 'plus'],
]
2023-02-14 14:27:11 +01:00
]);
}
}