Reputation: 1520
I have a two eloquent and this is the code on each of them without union
.
So I want to get all styles
based on the logged user that is from his organizations
and schools
$organization_styles = Auth::user()->teacher->school->organization->styles;
$school_styles = Auth::user()->teacher->school->styles;
echo "<pre>";
print_r($organization_styles->toArray());
echo "</pre>";
echo "------------------------";
echo "<pre>";
print_r($school_styles->toArray());
echo "</pre>";
and this is the result.
I want to union it and this is my current test but it gave me error
$test = $school_styles->union($organization_styles);
Upvotes: 1
Views: 5305
Reputation: 40899
Collection class does not have a union() method. You're gonna need to use merge() method. It should do exactly what you need - it will merge the two collections and make sure styles are not repeated:
$styles = $school_styles->merge($organization_styles);
Upvotes: 2