Giter VIP home page Giter VIP logo

laravel-multiauth's Introduction

Laravel-Multiauth

Latest Stable Version Total Downloads Latest Unstable Version License

A Simple Laravel Package for handling multiple authentication

##Step 1 : Require Composer package##

Open your terminal and navigate to your laravel folder. Now run the following command

composer require sarav/laravel-multiauth

or

"require": {
    "sarav/laravel-multiauth": "^0.0.5"
}

##Step 2 : Replacing default auth service provider##

Replace  "Illuminate\Auth\AuthServiceProvider::class" with "Sarav\Multiauth\MultiauthServiceProvider::class"

##Step 3 : Modify auth.php##

Modify auth.php file from the config directory to something like this

'multi' => [
    'user' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
        'table'  => 'users'
    ],
    'admin' => [
        'driver' => 'eloquent',
        'model'  => App\Admin::class,
        'table'  => 'admins'
    ]
 ],

Note : I have set second user as admin here. Feel free to change yours but don't forget to add its respective driver, model and table.

We are done! Now you can simply login user/admin like the following code

\Auth::loginUsingId("user", 1); // Login user with id 1

\Auth::loginUsingId("admin", 1); // Login user with id 1

// Attempts to login user with email id [email protected] 
\Auth::attempt("user", ['email' => '[email protected]', 'password' => 'password']);

// Attempts to login admin with email id [email protected]
\Auth::attempt("admin", ['email' => '[email protected]', 'password' => 'password']); 

Simply pass the first parameter as key which you have configured in auth.php to perform authentication for either user or admin.

For more information check out this article.

laravel-multiauth's People

Contributors

sarav-s avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.