Support the ongoing development of Laravel.io →
Database Eloquent Views

So I have a view where I loop through then display a company's employees into a table.

We are implementing a system where the owner of the company can allow or restrict access to portions of the application on a per employee basis. our plan is to add a toolbox for reach record in the table where owners can set individual permissions to 'active' or 'inactive', choose from a set of default permissions, or click a master 'active' and master 'inactive' button just in case they want everyone to have all the things.

My thought was to sort of extend my current code and add another variable or method useable by a user record to bring in the results of a partial view pre-filled with their information ( in this case, their permissions ).

To explain further, I am wondering if there is anything similar to a 'scope' method where I can call it like this:

{{ $user->permissionsPartial() }}

or, maybe something during the Eloquent call like this:

$users = User::permissionsPartials()->get();
//then access it in the view like so...
{{$user->permissionsPartial->view}}

That way I can just call that method during any eloquent call for users and access that permissions partial view in any part of the application without having to make calls from the view.

I guess I could just create a method in the User model that I can access as I loop through each user, but I want to keep consistent with separation of concerns here. So that's why I'm wondering if anyone has thought of anything for this situation??

Last updated 3 years ago.
0

Any ideas?

0

just query that uses data and then show that uses data only in the view via the authentication.

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

ayyobro ayyobro Joined 25 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.