-2

I'm currently working on a project on laravel 8. I have 3 tables : 1.customers 2.books 3.loans I want to be able to make a request like $data=DB::table('emprunts')->where('customerid',$id->number)->first(); but where it would count the instances of loans with this customerid and return it into a variable.

I tried with

$limitemprunts = Emprunt::WhereIn('clientid',$search_text)->where('clientid',$search_text)->distinct()->get()->count();

but it gives me this error :

TypeError Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given, called in C:\xampp\htdocs\120\120\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php on line 919

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
YesItsMe
  • 13
  • 6
  • The error message is pretty clear - you're supplying a string instead of an array. I suspect that the source is `WhereIn`, which expects multiple entries. Turn your string into an array and feed it as such. – El_Vanja Apr 15 '21 at 08:57
  • Also, it doesn't really make any sense to call both `WhereIn` and `where` in the same query, on the same column, with the same value. It's either one or the other, it can't be both. – El_Vanja Apr 15 '21 at 08:58

2 Answers2

0

You will need to convert the second parameter of whereIn into an array:

$limitemprunts = Emprunt::WhereIn('clientid',[$search_text])->distinct()->get()->count();
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
0

As said in the comment, the answer was really simple : feed it an array

YesItsMe
  • 13
  • 6