0

I use this query and i get a error :

$description = $request->get('description');
                $description_query = Transcationhistorique::where(function ($query) use ($description, $user_id) {
                    $query->where('receiver_id', $user_id,'description', 'LIKE','%' . $description . '%')
                        ->orWhere('description', 'LIKE','%' . $description . '%','sender_id', $user_id);
                })->get();

and this is the error that I get :

"SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from transcation_historique where (sender_id = 32 and 0 = %salaire% and 1 = LIKE and 2 = description) or receiver_id = 32)"

and this what really i want to run:

select * from `transcation_historique` where (`sender_id` = 32 and `description` = %salaire%) or (`receiver_id` = 32 and `description` = %salaire%)
Ahmed Guesmi
  • 350
  • 7
  • 26

4 Answers4

5

try this

Transcationhistorique::where(function ($query) use ($description, $user_id) {
            $query->where(['receiver_id' => $user_id, 'description' => 'LIKE %' . $description . '%'])
                ->orWhere(['description' => 'LIKE %' . $description . '%', 'sender_id' => $user_id]);
        })->get();
Ahmed Atoui
  • 1,506
  • 1
  • 8
  • 11
1

Then you should use the following statement:

$query = Transcationhistorique::where(function ($query) use ($description, $user_id) {
      $query->where('receiver_id', $user_id)
          ->where('description', 'LIKE','%' . $description . '%');
})
->orWhere(function ($query) use ($description, $user_id) {
      $query->where('sender_id', $user_id)
          ->where('description', 'LIKE','%' . $description . '%');
})
->get();
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50
0

You should try this:

$description = $request->get('description');
$query = Transcationhistorique::where(function ($query) use ($description, $user_id) {
      $query->where('receiver_id', $user_id)
          ->where('description', 'LIKE','%' . $description . '%');
})
->orWhere(function ($query) use ($description, $user_id) {
      $query->where('sender_id', $user_id)
          ->where('description', 'LIKE','%' . $description . '%');
})
->get();
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
0

Or try This with Query Builder :

$description_query = DB::table('transcationhistoriques')
            ->where(['receiver_id' => $user_id, 'description' => 'LIKE %' . $description . '%'])
            ->orWhere(['description' => 'LIKE %' . $description . '%', 'sender_id' => $user_id])
            ->get();