You can for example merge both collections.
$mergedProducts = $this->products_1->merge($this->products_2);
dd($mergedProducts->all());
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to combine models into a single query.
I made a dependent dropdown upon click shows other tables. However, for whatever reason, after the page displays the other table, the only data being displayed is whatever data is inside the current model.
Here is what everything looks like BEFORE anything is pressed:
Here is my first backend query:
Here is the result:
If I switch out the models, the other table's data is displayed:
Interestingly enough, if I enable BOTH queries, it takes the bottom-most query, as shown below:
Here is everything inside of the function, if it helps gather more information, as well as the blade file itself:
Is there any way to combine two models in a single query? Obviously, the joins for whatever reason are not holding up, and am wondering if am at the limits of what can be done with 3 levels of dependent dropdowns.
@Jdubstep1357 Ok ... well ... class_location is not the relationship but the table name.
I suggest you to follow some tutorials to discover Laravel from scratch. Here on Laracast you have a lot of great series.
https://laracasts.com/series/laravel-8-from-scratch
And sure you have the Laravel documentation.
And the part which explains the relationships.
Please or to participate in this conversation.