I'm building my first project in laravel and I have an index page where I want to show 4 different lists (they're different categories of the same data, and users will have permissions to see one or more of the lists)
The format for the lists (name, link, image, etc) is identical so I made a partial for it, with the idea that on this index page I'd check the authenticated user and if they have permission for list A then show it, if they have permission for list B then show it, etc.
To try it out, I made a scope for the first category (in my controller), and it shows the right data when I pass it to a totally separate view. But I'm unclear on how/whether I can display the partial multiple times on the index view with a different scope each time. What's the right way to go about this?
I imagined I would do something like check the permissions one at a time, make a variable with just that scope of data, and show the partial for just that data, like:
@include ('partials._items_list') , $category_A)
But the comment here suggests that a view has only one scope of data at a time (so maybe my idea isn't a valid thing): Laravel - Modify and return variable from @include
You can pass different values with the same partial using something like the following:
@include ('partials._items_list') , ['categoey_A' => $category_A]);
@include ('partials._items_list') , ['categoey_A' => $category_B]); // <-- Different Value
Use only {{ $categoey_A }}
in your partials._items_list
view but output will be different.