UserController.php
919 Bytes
<?php
namespace App\Http\Container\ProviderSection\Controllers;
use App\Models\User;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiController;
use Illuminate\Http\Request;
class UserController extends ApiController
{
/**
* @param \Illuminate\Http\Request $request
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function __invoke(Request $request): Response
{
$pageSize = $request->get('pageSize', 20);
$fetchType = $request->get('fetchType', 'page');
$filter = $request->except(['page', 'pageSize', 'fetchType']);
$build = User::filter($filter)->select(['id', 'nick_name', 'avatar'])->where('audit_status', 1)->latest('id');
return match ($fetchType) {
'all' => $this->successWithData($build->get()),
default => $this->successWithData($build->paginate($pageSize))
};
}
}