Tuesday, May 23, 2017

Redirect After Login for each role create with Shinobi Package Laravel

i have a question, i want to redirect users to diferent pages after login based in the role, if is admin redirect to admin/users if is normal redirect to admin/norma for example i have the next files

LoginController.php

    <?php

     namespace App\Admin\Http\Controllers\Auth;

     use App\Admin\Http\Controllers\Controller;
     use Illuminate\Foundation\Auth\AuthenticatesUsers;
     use Illuminate\Http\Request;

     class LoginController extends Controller
     {
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;

/**
 * Where to redirect users after login.
 *
 * @var string
 */

protected $redirectTo = 'admin/users';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest', ['except' => 'logout']);
}

/**
 * Validate the user login request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return void
 */
protected function validateLogin(Request $request)
{

    $this->validate($request, [
        $this->username() => 'required', 'password' => 'required', //'g-recaptcha-response' => 'required|recaptcha',
    ]);
}

}

And i use Laravel 5.3 and the Shinobi Package for roles and permissions https://github.com/caffeinated/shinobi

I already create 4 roles in the system database table roles - Administrador/Free/Gold/Diamond

I thinks is something how this

    if($user->rol = 'Administrador){
       protected $redirectTo = 'admin/users';
    }else{
       protected $redirectTo = 'admin/normal';
    }

But i dont know how exactly make to work, thanks for all.



via Alan Cordova

Advertisement