Rumah > Soal Jawab > teks badan
Apabila membuka semua laluan, ia menunjukkan terlalu banyak ubah hala Mengapa ini?
Route::group([],function(){
Route::get('/', function () {
return view('shouye');
});
Route::get('/123', array('as'=>'list','uses'=>function () {
return route('list');
}));
Route::get('/456', ['middleware'=>'login','uses'=>function () {
return 456;
}]);
});
<?php
namespace App\Http\Middleware;
use Closure;
class LoginMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(!session('uid')){
return redirect('/123');
}
return $next($request);
}
}
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\LoginMiddleware::class,
];
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'login'=>\App\Http\Middleware\LoginMiddleware::class,
];
習慣沉默2017-06-22 11:56:12
Poster meletakkan LoginMiddleware
这个中间件加在了Http/Kernel.php
文件中的$middleware
dalam pembolehubah, yang bermaksud bahawa setiap permintaan akan melalui laluan ini
Dengan cara ini, arah akan ditakrifkan semula setiap kali /123
这个路由上;而/123
自身这个请求,也需要通过LoginMiddleware
Perisian tengah ini secara semula jadi adalah gelung tak terhingga