在Laravel成功登录后,无法将用户重定向到自定义URL

时间:2017-04-29 16:44:40

标签: laravel-5

我尝试在成功登录后将用户重定向到自定义URL,但它不起作用。它会将用户重定向到此仪表板页面“/”。我已经将网站部署到服务器,因此我无法使用工匠清除路由缓存。

Laravel版本是5.3.29

应用\ HTTP \控制器\验证\ LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected $redirectTo = '/my-profile';
    protected $redirectPath = '/my-profile';

    protected function redirectTo()
    {
        return '/my-profile';
    }

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

应用\ HTTP \中间件\ RedirectIfAuthenticated.php

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check())
        {
            return redirect('/my-profile');
        }

        return $next($request);
    }
}

我已经读过在this帖子中Laravel可能存在一些问题。它说这个文件可能有一些问题:/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUser.php,但这个错误在Laravel版本5.3.29中得到修复,但我可以看到它是fixed和'returnTo'方法应该有效。

/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUser.php

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Support\Facades\Log;

trait RedirectsUsers
{
    /**
     * Get the post register / login redirect path.
     *
     * @return string
     */
    public function redirectPath()
    {
        Log::info("RedirectsUsers");
        if (method_exists($this, 'redirectTo')) {
            return $this->redirectTo();
        }

        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/homeeeee';
    }
}

我的路线档案:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

Auth::routes();

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

Route::get('/home', 'HomeController@index');

Route::get('/confirm-your-email', 'Auth\ConfirmEmailController@confirm_email');

Route::get('/confirm-email/{register_token}', 'Auth\ConfirmEmailController@index');

Route::get('/my-profile', ['as' => 'my-profile' , 'uses' => 'MyProfileController@show', 'userAlert' => null]);

Route::post('/my-profile/edit-about', 'MyProfileController@editAbout');

Route::post('/my-profile/edit-profile-picture', 'MyProfileController@editProfilePicture');

Route::get('/search/company', 'SearchController@searchCompany');

Route::get('/my-profile/add-job', 'MyProfileController@addJobPage');

Route::get('/my-profile/add-job/{id}', 'MyProfileController@addCompanyJobPage');

Route::post('/my-profile/add-a-job', 'MyProfileController@addJob');

Route::post('/my-profile/delete-job', 'MyProfileController@deleteJob');

Route::get('/users/{id}', ['as' => 'users', 'uses' => 'UserController@show']);

Route::get('/rate/user/{id}', ['as' => 'rate', 'uses' => 'RateController@showUserRate']);

Route::post('/rate/rate-user/{id}', 'RateController@rateUser');

Route::get('/invite-user-rate/{id}', 'RateController@showInviteUserToRateYou');

Route::post('/invite-rate/user/{id}', 'RateController@inviteUserToRateYou');

Route::get('/company/{id}', ['as' => 'company', 'uses' => 'CompanyController@show']);

Route::get('/rate/company/{id}', 'RateController@showCompanyRate');

Route::post('/rate/rate-company/{id}', 'RateController@rateCompany');

Route::get('/search/{page}/results/', 'SearchController@showSearchCompanies');

Route::get('/search/{page}/people/results', 'SearchController@showSearchPeople');

Route::get('/leave-a-rating/', 'SearchController@showLeaveARating');

Route::get('/invite', ['as' => 'invite', 'uses' => 'OtherAuthentificatedController@showInvite']);

Route::post('/email-invite', 'OtherAuthentificatedController@emailInvite');

Route::get('/contact', 'OtherController@showContact');

Route::post('/send-contact-email', 'OtherController@sendContact');

Route::get('/tyfcu', 'OtherController@thankYouForContactingUs');

1 个答案:

答案 0 :(得分:0)

您可以在服务器上运行此命令以获取清除密码 如果你想 php artisan cache:clear

并且对于重定向,您可以通过此方法重定向 return Redirect :: route(&#39; / my-profile&#39;);

认为这可能会对你有所帮助