I'm trying to build a web app using laravel for the backend! I used the php artisan make:auth command to generate the basic login logic and views. Now I'm trying to redirect users according to the admin field in the users table in the database. The problem is this : it think i don't get the right values from the db so the redirect never works...
here is the routes.php
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/register', function () {
return redirect('/step1');
});
route::get('/dashboard', function () {
return view('admin.dashboard');
});
// after login --> else "welcome"
Route::get('/home', 'HomeController@index');
// register user + agency
Route::get('/step1', 'AgencyController@showStep1');
Route::post('/step1', 'Auth\AuthController@register');
// complete registration step 2 --> 9
Route::get('/step{stepId}', ['middleware' => 'auth', 'uses' => 'AgencyController@show']);
Route::post('/step{stepId}', 'AgencyController@store');});
Here is the code for the redirect (in AuthController.php)
<?php
namespace App\Http\Controllers\Auth;
use App\Agency;
use App\Http\Controllers\Controller;
use App\User;
use Auth;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Http\Request;
use Validator;
class AuthController extends Controller {
/*
|------------------------------------------------------------------- -------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct() {
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
public function login() {
if (Auth::check()) {
if (Auth::User()->admin != '1') {
return redirect('/dashboard');
} else {
return redirect('/step1');
}
} else {return 'doesnt work :(';}
}
when i run this and login i always get the 'doesnt work' text.
NOTE: the Auth command generated routes :
$this->get('login', 'Auth\AuthController@showLoginForm');
$this->post('login', 'Auth\AuthController@login');
$this->get('logout', 'Auth\AuthController@logout');
// Registration Routes...
$this->get('register', 'Auth\AuthController@showRegistrationForm');
$this->post('register', 'Auth\AuthController@register');
thanks in advance !