skip to Main Content

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


  1. Try changing tickets($type = '',Request $request) to tickets(Request $request), the type should be part of the request, which you can check by adding a dd($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 do switch ($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 either Seller Request or from 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.

    Login or Signup to reply.
  2. I think the problem is when you pass empty string

    Use query params.change route like this if you want to pass empty value.

    /tickets?type=
    

    And access the value like this.

    public function tickets(Request $request){
    
     $type = $request->type;
    
    }
    

    Suggestion: use when() instead of switch for conditional query statements

    Login or Signup to reply.
  3. Route::get('tickets','TicketController@tickets')->name('admin-tickets')
    
    
    public function tickets(Request $request){ 
         $type = $request->type;
    }
    
    
    
    /tickets?type=
    

    You can validate the ticket query parameter using request object in controller’s ticket method.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search