Support the ongoing development of Laravel.io →
Security Input Packages
Last updated 3 months ago.
0

Hi ! I don't know whether my question seems silly or not ! but I have to ask ! I even checked the source code but I didn't find any method which give me the Role object by name ! let's consider I have a Role called "Admin" and also I have another Role which is "simpleUser" when the user is registering I want to automatically the admin role which is saved in database assign to my user. but how should i first get the Role by name and then attach role to my user. sorry if i'm just asking silly question ! thanks !

Last updated 3 months ago.
0

Hi majidphpdeveloper,

Assuming you have both Confide and Entrust and followed the install guides for both, you should have a UsersController.php generated by Confide. I would suggest attaching the role to the user when they confirm their account, so in your UsersController.php, look for the confirm() method:

/**
 * Attempt to confirm account with code
 *
 * @param  string $code
 *
 * @return  Illuminate\Http\Response
 */
public function confirm($code)
{
...etc...

In there, you should see an if condition checking for a valid confirmation code. Just before the redirect, try this:

Confide::user()->attachRole('role name');

If that doesn't work, try attaching the role when the account is created instead. In your store() method, try this:

/**
 * Stores new account
 *
 * @return  Illuminate\Http\Response
 */
public function store()
{
    $repo = App::make('UserRepository');
    $user = $repo->signup(Input::all());

    if($user->id)
    {
        $user->attachRole('role name');
        ...etc...

Good luck!

Last updated 3 months ago.
0

Hi there,

I am looking for a way to grant different roles/permissions to certain instances of a model. E.g. User A gets an Admin-Role on Project 1, is Editor on Project 2 and Reviewer on Project 3. User B is Reviewer on Project 1, Admin on Project 2 and has no rights on Project 3. All permissions are managed globally for the roles. Is this possible with entrust? Does anybody know some articles, tutorials or cases. Would be great, thanks!

Last updated 3 months ago.
0

Hi,

Awesome package! ... but... Why do you have a column id in the pivot tables? It should only have the id of table A and the id of table B, and both of them would form the primary key of the pivot table, this should be the appropriate way to do it. I had to create a unique key with the fk of each table in order to simulate the correct way of building the pivot table. Any special reason why you used the incremental id as the primary key of the pivot tables(assigned_roles, permission_role)?

Cheers

Last updated 3 months ago.
0

Has anyone create administration for confide/entrust user/roles managment?

Last updated 3 months ago.
0

kamaji said:

Hi there,

I am looking for a way to grant different roles/permissions to certain instances of a model. E.g. User A gets an Admin-Role on Project 1, is Editor on Project 2 and Reviewer on Project 3. User B is Reviewer on Project 1, Admin on Project 2 and has no rights on Project 3. All permissions are managed globally for the roles. Is this possible with entrust? Does anybody know some articles, tutorials or cases. Would be great, thanks!

I'm in the same boat, and am thinking global scopes are the way to go. Not sure how that will play with Entrust, but am looking at this right now as a possible help: https://github.com/globecode/laravel-multitenant

Last updated 3 months ago.
0

@dambridge & @kamaji did any of you guys come up with a solution to this? I'm in the same situation.

Last updated 3 months ago.
0

i cannot find any entrust version for PHP 5.3.0

Last updated 3 months ago.
0

abhitheawesomecoder said:

i cannot find any entrust version for PHP 5.3.0

PHP 5.3 reached End of Life in August and the minimum version supported by Laravel is 5.4. You should really consider upgrading.

Last updated 3 months ago.
0

Is there a common method of auto-populating the roles table with default data? I've tried a couple of different techniques, but I can't get my tests to pass. I am automatically assigning a role using an observer, and if the role doesn't exist in the database, the test fails. However, if I seed my roles table before testing, I get a bunch of "roles table already exists" errors from other tests.

Things that don't work:

  • calling $this->seed('Database\Seeds\RolesTableSeeder'); from my prepareForTests() method.
  • detecting the testing environment from within the observer and seeding the database if necessary.

I wouldn't mind unbinding the observer during testing, as long as I can selectively re-enable it during tests for which it is needed. Any suggestions?

Last updated 3 months ago.
0

Hi, i just read about your package and it awesome but i have something in my mind for role/permission in my web, what if i already define new roles, define new permission and already attach that to some of my users and i willing to give ability to change permission and roles in the future... how to do that? since i already do something like

    $admin = new Role();
    $admin->name = 'Admin';
    $admin->save();
  
    $user = new Role();
    $user->name = 'User';
    $user->save();
  
    $read = new Permission();
    $read->name = 'can_read';
    $read->display_name = 'Can Read Data';
    $read->save();
  
    $edit = new Permission();
    $edit->name = 'can_edit';
    $edit->display_name = 'Can Edit Data';
    $edit->save();
  
    $user->attachPermission($read);
    $admin->attachPermission($read);
    $admin->attachPermission($edit);
 
    $adminRole = DB::table('roles')->where('name', '=', 'Admin')->pluck('id');
    $userRole = DB::table('roles')->where('name', '=', 'User')->pluck('id');
    // print_r($userRole);
    // die();
  
    $user1 = User::where('username','=','imron02')->first();
    $user1->roles()->attach($adminRole);
    $user2 = User::where('username','=','asih')->first();
    $user2->roles()->attach($userRole);
    $user3 = User::where('username','=','sarah')->first();
    $user3->roles()->attach($userRole);

but like say after i run this code, i want to change $user3 roles to be $adminRole... how to do that? write the same code and execute again but this time like this?

$user3->roles()->attach($adminRole);
Last updated 3 months ago.
0

what is the use of permission_role table in the database ?

0

PureSingh said:

what is the use of permission_role table in the database ?

This is a pivot table that relates roles to permissions.

0

How to show the user Role on the blade view. I have a view to show the all user, so i used the foreach loop. Now i also want to show the role of user with other details. I know i can do that by using join. Is there any simple way to do this ? Thank you.

Last updated 7 years ago.
0

For all who need it, I forked Entrust and converted it to Laravel 5.

Please report any issue in the Github issues page.

Thanks

< The fork has been merged back to the original Zizaco/Entrust repo. >

Last updated 7 years ago.
0

Is there any way to get role by name?

0

Hi All,

I'm new to laravel and just don't know what to do from the point Usage -> Concepts ->
$owner = new Role;
$owner->name = 'Owner';
$owner->save();

$admin = new Role;
$admin->name = 'Admin';
$admin->save();

where do I place this code and how to run it? Or can I just create these records in the table??

thanks in advance!

Last updated 7 years ago.
0

Hi All,

I'm quite new to Laravel (Entrust/Confide).

I got Confide to work well but with one issue though; the email part setup correctly with Gmail: smtp but doesn't want to send to other Gmail account besides the one I used to send the email which is my email address.

ISSUE 1: The issue above is, whenever I create another Gmail account - it actually creates the account but without sending confirmation email to the new Gmail address. I could see it in the database.

My solution here is to seed the data manually and set confirmation=1, then I can log in with the newly created user email address.

Can someone please shed more light on this for me ... I'm I doing something wrongly?

ISSUE 2: If I want to start the process afresh and I truncate USERS table, then if I created my account afresh; though email confirmation is sent but when I click on the link in my email to take me to the login page of my app it gives error!

I don't understand this part as well. I need more light here.

Finally: ENTRUST

I've setup Entrust with Roles and Permissions

I've attached permissions to roles and to a particular user but doesn't seem to e working.

I used something like below in my filter.php file:

Folder finance have 2 pages: register_finance and view_finance

Role: manager permission: manage_finance

With manager role, one should be able to access those 2 pages - I do I do this?

Route::filter('manage_finance', function() { if (! Entrust::can('manage_finance') ) { // Checks the current user

return Redirect::to('/'); -- Confused here, as I have 2 routes in finance/* } });

// Only users with roles that have the 'manage_finance' permission will // be able to access any finance/* routes. Route::when('finance/*', 'manage_finance');

My question is: with manager role, one should be able to access those 2 pages - I do I do this?

Thank you !

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.