I trying to make a login and admin script, the problem is that I have a redirect loop I dont know why.
I want the login users and can be in the /
path not /home
.
If change return new RedirectResponse(url('/'));
to return new RedirectResponse(url('/anotherpage'));
it works but I want to be /
Routes:
Route::get('/', [
'as' => 'home', 'uses' => 'HomeController@index'
]);
// Tutorials Routes
Route::get('/tutorials', 'HomeController@tutorials');
Route::get('/tutorials/{category?}', 'HomeController@tutorialsCategory');
Route::get('/tutorials/{category?}/{lesson?}', 'HomeController@tutorialsLesson');
// Courses and Series Routes
Route::get('/courses-and-series', 'HomeController@coursesandseries');
// Admin Routes
Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function()
{
Route::get('/admin', function()
{
return 'Is admin';
});
});
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Admin middleware:
public function handle($request, Closure $next)
{
if (Auth::user()->type != 'Admin')
{
return abort(404);
}
return $next($request);
}
RedirectIfAuthenticated:
public function handle($request, Closure $next)
{
if ($this->auth->check())
{
return new RedirectResponse(url('/'));
}
return $next($request);
}
Home Controller:
class HomeController extends Controller {
public function __construct()
{
$this->middleware('guest');
}
public function index()
{
return view('home');
}
public function tutorials()
{
return view('pages.tutorials');
}
public function tutorialsCategory()
{
return view('pages.tutorials');
}
public function tutorialsLesson()
{
return view('pages.single');
}
public function coursesandseries()
{
return view('pages.coursesandseries');
}
public function single()
{
return view('pages.single');
}
}