Monday, April 30, 2018

Laravel 5.2 Login With Condition - development

Laravel 5.2 Login With Condition

So, I have users table which is default by laravel. But I add a new column named ‘status’.

So the columns on the users table are id, name, email, password, remember_token, created_at, updated_at, status

The status values are between 0 and 1. 1 for admin, and 0 for regular user.

Also I have auth, but the problem is how can I check if users’ status is 0 or 1 when login so that I can redirect it according to their status? — admin will go to admin panel and user will go to home

User default by laravel with addition ‘status’

use IlluminateNotificationsNotifiable;
use IlluminateFoundationAuthUser as Authenticatable;

    class User extends Authenticatable
    {
        use Notifiable;
        protected $fillable = [
            'name', 'email', 'password', 'status',
        ];
        protected $hidden = [
            'password', 'remember_token',
        ];
    }

HomeController also default by laravel

use IlluminateHttpRequest;

class HomeController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
        return view('home');
    }
}

LoginController also default by laravel

use AppHttpControllersController;
use IlluminateFoundationAuthAuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;
    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

THANKS.



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-5-2-login-with-condition/
via Lzo Media

No comments:

Post a Comment