adrema/app/Invoice/Actions/InvoiceIndexAction.php

39 lines
963 B
PHP
Raw Permalink Normal View History

2023-12-16 01:13:49 +01:00
<?php
namespace App\Invoice\Actions;
use Lorisleiva\Actions\Concerns\AsAction;
use App\Invoice\Models\Invoice;
use App\Invoice\Resources\InvoiceResource;
2024-05-14 01:29:39 +02:00
use App\Invoice\Scopes\InvoiceFilterScope;
2023-12-16 01:13:49 +01:00
use Inertia\Inertia;
use Inertia\Response;
2024-12-16 14:18:02 +01:00
use Laravel\Scout\Builder;
2024-05-14 01:29:39 +02:00
use Lorisleiva\Actions\ActionRequest;
2023-12-16 01:13:49 +01:00
class InvoiceIndexAction
{
use AsAction;
/**
2024-12-16 14:18:02 +01:00
* @return Builder<Invoice>
2023-12-16 01:13:49 +01:00
*/
2024-12-16 14:18:02 +01:00
public function handle(InvoiceFilterScope $filter): Builder
2023-12-16 01:13:49 +01:00
{
2024-12-15 16:05:38 +01:00
return $filter->getQuery()->query(fn ($q) => $q->with('positions'));
2023-12-16 01:13:49 +01:00
}
2024-05-14 01:29:39 +02:00
public function asController(ActionRequest $request): Response
2023-12-16 01:13:49 +01:00
{
2023-12-16 13:08:17 +01:00
session()->put('menu', 'invoice');
session()->put('title', 'Rechnungen');
2024-05-14 01:29:39 +02:00
$filter = InvoiceFilterScope::fromRequest($request->input('filter', ''));
2023-12-16 01:13:49 +01:00
return Inertia::render('invoice/Index', [
2024-12-15 16:05:38 +01:00
'data' => InvoiceResource::collection($this->handle($filter)->paginate(15)),
2023-12-16 01:13:49 +01:00
]);
}
}