I am trying to redirect the users to a custom URL after a succesful login but it doesn't work. It keeps redirecting users to this dashboard page "/". I already deployed the website to the server so I can't clear the route cache with artisan.
Laravel version is 5.3.29
App\Http\Controllers\Auth\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']);
}
}
App\Http\Middleware\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);
}
}
I have read that there might be some problems with Laravel in this post. It says that there might be some problems with this file: /vendor/laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUser.php, but this error was fixed in Laravel version 5.3.29, but I can see that it is fixed and 'returnTo' method should work.
/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';
}
}
And my routes file:
<?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');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire