Support the ongoing development of Laravel.io →
posted 7 years ago
Architecture
Last updated 2 years ago.
0

what if a doctor is an admin too? I've come across situations like this.

I would say keep auth table simple (single 'users' table). and then attach models of each role to the user model. The user model will have relationships to patient, admin and doctor models.

Also Laravel supports authentication from multiple tables. If you want to use multiple tables.

0

Thanks for your answer! this is the way I'm trying it now, I'm just wondering how to make the routes? My DashboardController looks like this now, it's bad... but i'm wondering where to add that checking logic

class DashboardController extends Controller
{

    public function index()
    {
        if(Auth::user()->hasRole('admin')) {
            return view('admin.index');
        }

        if(Auth::user()->hasRole('dentist')) {
            return view('doctor.index');
        }
    }

    public function settings()
    {
        if(Auth::user()->hasRole('admin')) {
            return view('admin.settings');
        }

        if(Auth::user()->hasRole('dentist')) {
            return view('doctor.settings');
        }
    }
}

Because there will be routes like /dashboard/settings , that will be there for all roles.

Thanks for your time!

Last updated 7 years ago.
0

Assuming a dentist could be an admin as well, you could move the role check to the view (or use view composer)

https://laravel.com/docs/5.3/views#view-composers

0

yes, use view composers.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

notflip notflip Joined 2 Sep 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.