adrema/app/Activity/Actions/IndexAction.php

32 lines
838 B
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-23 22:43:13 +01:00
$filter = ActivityFilterScope::fromRequest($request->input('filter'));
return Inertia::render('activity/VIndex', [
'data' => $this->handle($filter),
2023-02-14 14:27:11 +01:00
]);
}
}