ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Couldn't understand how to config auth.php #7

Closed fitbodylicious closed 10 years ago

fitbodylicious commented 10 years ago

Hi

I couldn't understand this part:

return array( 'multi' => array( 'account' => array( 'driver' => 'eloquent', 'model' => 'Account' ), 'user' => array( 'driver' => 'database', 'table' => 'users' ) ), 'reminder' => array( 'email' => 'emails.auth.reminder', 'table' => 'password_reminders', 'expire' => 60, ), );

how if I want to add 'admin'?

Lochnair commented 10 years ago

If you want to use the Eloquent driver with a model called Admin, it would look like this:

return array(
    'multi' => array(
        'account' => array(
            'driver' => 'eloquent',
            'model' => 'Account'
        ),
        'user' => array(
            'driver' => 'database',
            'table' => 'users'
        ),
        'admin' => array(
            'driver' => 'eloquent',
            'model' => 'Admin'
        ),
    ),

    'reminder' => array(
    'email' => 'emails.auth.reminder',
    'table' => 'password_reminders',
    'expire' => 60,
    ),
);
fitbodylicious commented 10 years ago

so I don't have to define which table to use?

Lochnair commented 10 years ago

Only if you use the database driver, if you use Eloquent models Laravel normally finds the table by itself.

fitbodylicious commented 10 years ago

how if I got a model name different with the table name? how do I define it?

thanks alot for your help!

Lochnair commented 10 years ago

Lets say you have the model Admin and want it to load from the table _authadmin, you would simply do this:

<?php
class Admin extends Eloquent {
    protected $table = "auth_admin";
}

Though the official docs has much more information on how to use Eloquent.

fitbodylicious commented 10 years ago

ahhh..that's great. thanks alot man for your help! really appreciate!

Lochnair commented 10 years ago

No problem, happy to help:) Btw you should close the issue.