0

I have a book[] input field that comes from the view

 $arr = $request->book_name;
 dd($arr);

the dd result is like

array:2 [
    0 => "1"
    1 => "3"
]

I want to select data from the library table where book_id match whit the above array, I wrote the below query but it gives an error like:

Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in D

the query is like this:

$libQuantity = \DB::table('library')->select('quantity')->whereIn('book_id', '=', $arr)->get();
2
  • Is there a Library Model? Commented Feb 11, 2021 at 4:55
  • yes there is Library Model Commented Feb 11, 2021 at 4:56

1 Answer 1

2

Try:

$libQuantity = \DB::table('library')
                    ->select('quantity')
                    ->whereIn('book_id', $arr)
                    ->get();

or

$libQuantity = \App\Models\Library::whereIn('book_id', $arr)
                    ->get(['library']);

The issue is

'book_id', '=', $arr should be 'book_id', $arr

Sign up to request clarification or add additional context in comments.

1 Comment

Hahah! I can't believe it was just because of =, thank you bro it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.