Laravel 5 Can';成功登录Laravel后,将用户重定向到自定义URL
我尝试在成功登录后将用户重定向到自定义URL,但它不起作用。它不断将用户重定向到此仪表板页面“/”。我已经将网站部署到服务器,因此无法使用artisan清除路由缓存 Laravel版本为5.3.29 App\Http\Controllers\Auth\LoginController.phpLaravel 5 Can';成功登录Laravel后,将用户重定向到自定义URL,laravel-5,Laravel 5,我尝试在成功登录后将用户重定向到自定义URL,但它不起作用。它不断将用户重定向到此仪表板页面“/”。我已经将网站部署到服务器,因此无法使用artisan清除路由缓存 Laravel版本为5.3.29 App\Http\Controllers\Auth\LoginController.php <?php namespace App\Http\Controllers\Auth; use Illuminate\Support\Facades\Log; use App\Http\Control
<?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']);
}
}
您可以在服务器上运行此命令以清除错误
如果你愿意
php artisan缓存:清除
对于重定向,您可以使用此方法重定向
return Redirect::route(“/my profile”)
我想这可能对你有帮助
<?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);
}
}
<?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');