Laravel problems to redirect after authenticating?

Asked

Viewed 640 times

0

I’m starting to learn how to use the Framework Laravel and I’m having a problem with directing after login, I’m using the login system itself Framework.

To learn how to use the Framework I’m creating a simple blog and it’s time to log in /admin even if I change the attribute protected $redirectTo = '/dashboard';

I wonder what it could be because I couldn’t find the bug?

As requested by friends below, follow the route code and class where I changed the redirectTo attribute.

Routes/web.php

<?php
    Route::get('/', function () {
        return view('welcome');
    });

    Auth::routes();
    Route::get('/admin', 'HomeController@index');

    Route::group(['prefix' => 'dashboard'], function() {
        Route::get('/','DashboardController@index');
    });

app Http Controllers Auth Logincontroller.php

<?php

    namespace App\Http\Controllers\Auth;

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

    class LoginController extends Controller{

    use AuthenticatesUsers;

    /**
    * Where to redirect users after login.
    *
    * @var string
    */
    protected $redirectTo = '/dashboard';

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

App/Http/Controllers/Homecontroller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('home');
    }
}
  • Hello Gabriel, can you put your file of routes here so people help you better? Where are you changing the $redirectTo?

  • Post your code @gabrielguedes, even if it is what comes in the Laravel and on top of that explain your procedure, there are two places to change depending on the way you are doing will cause this confusion even, remember it is not bug of Laravel. What is the version of your Laravel this is also important.

  • With the latest updates from Laravel, it is important to post which version exactly is using too...

  • The Laravel version is 5.3

  • Try to rotate the command php artisan cache:clear

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.