mysql - IN statement in Eloquent -
I am trying to execute these statements in the echo query. I tried to do this:
$ id = urldecode ($ id); $ News = news :: whereHas (use 'newsCategories', function ($ q) ($ id) {$ q-> where (' category_id ',' IN ',' ('. $ Id.') ') - & gt; By command (' created ',' character ');}) - & gt; get ();
But I get empty results
When I switch IN
to =
and the array I pass a number instead, I get the result. I did something wrong?
Then it works:
$ id = 2; $ News = news :: whereHas ('newsCategories', function ($ q) ($ id) {$ q-> where ('category_id', '=', $ id) - & gt; orderBy ('created_at' 'Desc');}) - & gt; get ();
You can enter where in
with an array of your code Checking for ...
$ news = news :: whereHas ('newscategories', use function ($ q) ($ array_of_ids) {$ q-> gt; ; Where in ('category_id', $ Array_of_ids) - & gt; orderbird ('created', 'character');}) - & gt; get ();
Just make sure you are actually passing in an array :)
Comments
Post a Comment