app/Http/Controllers/Admin/TicketController.php on line 17
ArgumentCountError: Too few arguments to function AppHttpControllersAdminTicketController::tickets(), 1 passed in
public function tickets($type = '',Request $request){
$arr = [
'Seller Request',
'I want to become a seller',
'seller request',
'Seller request',
];
if ($request->word){
$tickets = Ticket::where('id',trim($request->word))->orderByDesc('id')->paginate(100);
return view('admin.layouts.tickets.index',compact('tickets'));
}
switch ($type){
case '':
$tickets = Ticket::where('status','1')->where('from_support',null)->whereNotIn('title',$arr)->orderByDesc('id')->paginate(100);
break;
case 'Seller Request':
$tickets = Ticket::where('status','1')->whereIn('title',$arr)->orderByDesc('id')->paginate(100);
break;
case 'from support':
$tickets = Ticket::where('status','1')->where('from_support','1')->orderByDesc('id')->paginate(100);
break;
}
return view('admin.layouts.tickets.index',compact('tickets'));
}
Route::get('tickets/{type?}','TicketController@tickets')->name('admin-tickets');
A problem I don’t know how to solve
3
Answers
Try changing
tickets($type = '',Request $request)
totickets(Request $request)
, thetype
should be part of therequest
, which you can check by adding add($request);
before the$arr
. Then use$request->type
within the function as needed. Since the$type
is an optional parameter, if it’s not in the request, meaning that it will be null, then at the switch you could doswitch ($request->type ?? ''){
to keep the current behavior.If you don’t like the null coalesce operator, then an alternative could be to use a
default
case instead, so that if eitherSeller Request
orfrom support
is not found, then do the$tickets = Ticket::where('status','1')->where('from_support',null)->whereNotIn('title',$arr)->orderByDesc('id')->paginate(100);
with the default.I think the problem is when you pass empty string
Use query params.change route like this if you want to pass empty value.
And access the value like this.
Suggestion: use when() instead of switch for conditional query statements
You can validate the ticket query parameter using request object in controller’s ticket method.