samedi 27 janvier 2018

Controller constructor to check Auth middleware for two different guards

I have a dashboard view that shows certain contain depending on which user is viewing, whether it be an admin or just a regular user.

I can get my admins onto that page, but regular users aren't able to currently because of my middleware guard.

class DashboardController extends Controller {

    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    public function index()
    {
        return view('dashboard.index');
    }
}

The following code checks on each DashboardController call for auth:admins, but I want regular users to access this too, is there a way to check the auth middleware twice like so?

$this->middleware(['auth:admin','auth']);

So ideally it will check if you're an admin or just a regular auth user.

Also on my view page, when accessing properties of an admin I'm using:



Is this normal? I have an admin Model but I'm still accessing it via Auth::user() which feels strange to me, shouldn't it be Auth::admin()->admin_username



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nhuMXy
via IFTTT

Aucun commentaire:

Enregistrer un commentaire