skip to Main Content

I try many way but not fixed this error what can I do ?

There is code

Controller

$ticketId = Tickets::get('id');

$assig_user_name = DB::table('tickets')
        ->join('users', 'tickets.assigned_id', '=', 'users.id')
        ->select('users.id','users.name')
        ->where('tickets.id', '=', $ticketId)
        ->get();

When I dd $ticketId it works and show id’s what I want but in join it is not working.

3

Answers


  1. The SQLSTATE[HY093]: Invalid parameter number generally indicates that you have provided an incorrect number of placeholders in your query, and there is a mismatch between the number of placeholders and the number of values you are attempting to bind to those placeholders.

    You could try with:

    $assig_user_name = DB::table('tickets')
            ->join('users', 'tickets.assigned_id', '=', 'users.id')
            ->select('users.id','users.name')
            ->where('tickets.id', '=', ':ticketId')
            ->setBindings([':ticketId' => $ticketId])
            ->get();
    

    Another issue could be that $ticketId is an array so you need:

    $assig_user_name = DB::table('tickets')
            ->join('users', 'tickets.assigned_id', '=', 'users.id')
            ->select('users.id','users.name', 'tickets.*')
            ->whereIn('tickets.id', $ticketId->pluck('id')->toArray())
            ->get();
    
    Login or Signup to reply.
  2. $ticketId return collection if you are trying to get all the users that have ticket then in that case you can do something like that

    $ticketId = Tickets::select('id')->get();
    
    $assig_user_name = DB::table('tickets')
            ->join('users', 'tickets.assigned_id', '=', 'users.id')
            ->select('users.id','users.name')
            ->wherein('tickets.id',[$ticketId])
            ->get();
    
    Login or Signup to reply.
  3. Try this…

    $ticketsId = Tickets::select('id')->get()->toArray();
    
    $assig_user_name = DB::table('tickets')
            ->join('users', 'tickets.assigned_id', '=', 'users.id')
            ->select('users.id','users.name')
            ->whereIn('tickets.id', $ticketsId)
            ->get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search