Support the ongoing development of Laravel.io →
Authentication Security Session
Last updated 2 years ago.
0

is it possible at all or do i have to write my own auth driver for that and swap it?

Last updated 2 years ago.
0

i ended up using my own custom helper class. i used the tutorial found at http://www.mackhankins.com/blog/laravel/defining-your-own-helper-classes-in-laravel-4. i have an access_type table (access_type_id, access_type) and in my users table i have an access_type_id column that is a fk.

so i have something like this

class Helpers {
  public static function isAccessType($access_type) {
    // get the access_type of user logged in
    $result = User::where('users.id', '=', Auth::User()->id)
      ->join('access_types', 'access_types.id', '=', 'users.access_type_id')
      ->select('access_types.access_type')
      ->first();

    if (!$result) {
      return false;
    }

    // compare result against $access_type
    if ($result->access_type != $access_type)
    {
      return false;
    }

    return true;
    
  }
}

this is what i use if i want certain sections of the page to be displayed depending on the access type of the user logged in.

if you want it to be a filter, you'd have to do something similar in the filters.php file. i don't know if this is an "ideal" solution, but it's working so far for me. i came from CI so i'm still a bit new to laravel. if someone has a better solution, please share, i'd like to know another way of tackling this. hope this helps, if this is what you're looking for.

so let's say i want to display an edit button for administrators only, i would do...

@if (Helpers::isAccessType('administrator')
  {{ Form::submit('edit') }}
@endif
Last updated 2 years ago.
0

@keevitaja I am guessing from your keeper package that you had to go with swapping out the Auth driver and couldn't find a way to just extend Auth as you proposed....?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

keevitaja keevitaja Joined 2 Feb 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.

© 2024 Laravel.io - All rights reserved.