SingerController.php
1.27 KB
<?php
namespace App\Http\Container\AdminSection\Controllers\User;
use App\Excel\SingerExcel;
use App\Models\User;
use App\Support\Controller;
use Hikoon\LaravelApi\Facades\Response;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class SingerController extends Controller
{
/**
* @param \Illuminate\Http\Request $request
* @param \App\Http\Service\UserService $service
* @return \Hikoon\LaravelApi\Facades\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function index(Request $request): Response|BinaryFileResponse
{
$pageSize = $request->get('pageSize', 20);
$filter = $request->except(['page', 'pageSize']);
$build = User::withTrashed()->filter($filter)
->select(['id', 'nick_name', 'real_name', 'avatar', 'email', 'phone', 'area_code', 'sex', 'official_status', 'status', 'province', 'city', 'created_at', 'scope', 'business_id', 'audit_at'])
->with('business:id,nick_name,real_name,identity')
->where('identity', 1);
return match ($request->get('fetchType')) {
'excel' => SingerExcel::withBuilder($build)->download(),
default => $this->successWithData($build->paginate($pageSize))
};
}
}