Answer the question
In order to leave comments, you need to log in
Who faced such strangeness of laravel? How to explain?
The situation is this - if you make a request in this way
\Model\Ad::whereStatus(1)->whereIn("category_id", $this->data['categories']->map->only(['id']))->get();
\Model\Ad::whereStatus(1)->whereIn("category_id", $this->data['categories'])->get();
Answer the question
In order to leave comments, you need to log in
Maybe I'm not an expert, but
$this->data['categories']->map->only(['id'])
1. map is a method... how can they access the method as a property in the lara? And if you have a `map` property, then be careful, there is such a method in the lara, and inside there under the hood there is almost a comparison of property_exists() method_exists() and everything is magic, you can tweak your model and there will be a question "how is it in general works" and not "why it doesn't work"
2. only this is for sampling if you made a collection from the array
collect([ 'name' => 'vasia', 'age' => 30 ])->only('name') ; // [ 'name' => 'vasia' ];
Roles::get()->only(['id' => 1]); // object Roles#1 (id => 1, title = ...)
3.
to get a list of IDs you need $categories->pluck('id')->all(); // [1,2,3]
Regarding stretching for 5-6 seconds - you see, Lara has a lot of magic inside. She is probably either looking for or trying to make toString() which calls some kind of serialize() under the hood. In general, it works, but the query there will turn out to be a fierce game, WHERE id IN ({json}, {json}) and some other garbage will be done
Debug queries var_dump($query->toSql(), $query-> getBindings()); and you look.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question