dimanche 20 septembre 2015

Authenticate and login on a table/model other than user table in laravel 5.1

This is my first php project and first time using the laravel framework. I would like to authenticate on a table/model in laravel other than the users table. After doing some research on the laravel forums it seems like the best way to accomplish this is middleware. So I came across this similar question on stack.

question here

here is the middleware from that question:

<?php namespace App\Http\Middleware;

use Closure;

class ChangeUserToAdmin
{

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        \Config::set('auth.table', 'admins');
        \Config::set('auth.model', 'App\DB\Admin\Admin');

        \Config::set('session.cookie', 'admin_session');
        \Config::set('session.path', '/admin/');

        return $next($request);
    }

}

I think my question is different from this because

  • -I'm asking if I can do this without a users table to begin with, but still use the out of box authentication

  • -Do I make a users table for the schema and extend it to work with the table that I actually want to use? ex: account_login_table

  • -What is this middleware actually changing?

  • -How do I know it's working with the main login form and how am I using it to protect my routes?

Any help would be appreciated, thanks.Simply all I want to really do is change the table against which it checks username and password and not have the default users table !



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire