我正在编写用户在单独的页面中接受条款和条件的逻辑,这是工作流程。
/welcome
页。/accept
我已设置以下路线:
Auth::routes();
// Temp
Route::get('/', function () {
return redirect('/login');
});
Route::get('/logout', 'Auth\LoginController@logout');
Route::post('password/reset/{token}', 'Auth\ResetPasswordController@postReset')->name('password.request');
// Auth middleware
Route::group(['middleware' => ['auth']], function () {
// Temp
Route::get('/discovery', function () {
return view('pages.discovery');
});
// Temp
Route::get('/welcome', function () {
return view('pages.welcome');
});
Route::get('/accept', 'Auth\LoginController@accept');
});
问题是当用户登录时,重定向到/welcome
页面而不是他们点击“接受”按钮以重定向到/accept
路由,然后它会中断公共消息{{ 1}}
我猜它与中间件有关。有什么想法吗?
更新
Sorry, the page you are looking for could not be found.
这是中间件:
// Auth middleware
Route::group(['middleware' => ['auth']], function () {
Route::get('/accept', 'Auth\LoginController@accept')->name('terms.accept');
Route::get('/welcome', function () {
return view('pages.welcome');
});
Route::group(['middleware' => ['terms']], function () {
Route::get('/discovery', function () {
return view('pages.discovery');
});
});
});
答案 0 :(得分:1)
Auth::routes();
Route::get('/', function () {
return redirect('/login');
});
Route::get('/logout', 'Auth\LoginController@logout');
Route::post('password/reset/{token}', 'Auth\ResetPasswordController@postReset')->name('password.request');
Route::group(['middleware' => ['auth']], function () {
Route::get('/accept', 'Auth\LoginController@accept')->name('get.accept');
Route::group(['middleware' => ['terms']], function () {
Route::get('/discovery', function () {
return view('pages.discovery');
});
Route::get('/welcome', function () {
return view('pages.welcome');
});
});
});
php artisan make:middlware Terms
<?php
namespace YourNamespace;
use Closure;
class Terms
{
public function handle( $request, Closure $next, $guard = null )
{
if( ! $request->user()->accepts_terms ) {
return redirect( route( 'get.accept' ) );
}
return $next( $request );
}
}
添加到您的HTTP内核routeMiddleware,'terms'=&gt; YourNewTermsMiddleware ::类