adrema/app/Initialize/Actions/NamiSearchAction.php

48 lines
1.2 KiB
PHP

<?php
namespace App\Initialize\Actions;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\Data\MemberEntry;
use Zoomyboy\LaravelNami\Nami;
class NamiSearchAction
{
use AsAction;
/**
* @param array<string, mixed> $params
*
* @return LengthAwarePaginator<MemberEntry>
*/
public function handle(Api $api, int $page, array $params): LengthAwarePaginator
{
return $api->pageSearch($params, $page, 10);
}
/**
* @return array<string, string>
*/
public function rules(): array
{
return [
'mglnr' => 'required|numeric|min:0',
'password' => 'required|string',
'params' => 'array',
];
}
/**
* @return LengthAwarePaginator<MemberEntry>
*/
public function asController(ActionRequest $request): LengthAwarePaginator
{
$api = Nami::login($request->input('mglnr'), $request->input('password'));
return $this->handle($api, $request->input('page', 1), $request->input('params'));
}
}