0

How can I do authentication with multiple database table in Laravel?

For example, I have 3 tables: 1. General User Login table 2. Membership detail table 3. CMS user detail table

When user login from the CMS or the member login, the Auth will go and verify from the "general user login" table. But how can I make the Auth function also getting info from the second or third table depend on the user type? Then, I can access those info via something like Auth::user()->address, which the address is stored in the membership detail table.

Thank you.

1

1 Answer 1

3

Create relationship columns, to relate your user to data in other tables:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    public function membership()
    {
        return $this->belongsTo('Membership');
    }

    public function userDetails()
    {
        return $this->belongsTo('CmsDetail');
    }

}

class Membership extends Eloquent {

    protected $table = 'membership';

}

class CmsDetail extends Eloquent {

    protected $table = 'cms_details';

}

Then you can just

echo Auth::user()->membership->member_since;

echo Auth::user()->userDetails->address;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.