我試圖通過以下代碼將管理員重定向到儀表板頁面,但是當我輸入/dashboard
時,瀏覽器顯示一個NotFoundHttpException
錯誤頁面。
中間件(AdminCheck.php):
對不起,找不到您正在尋找的頁面。 laravel
<?php
namespace App\Http\Middleware;
use Closure;
class AdminCheck
{
public function handle($request, Closure $next)
{
$user = auth()->authenticate();
if ($user->role !== 'admin')
{
return redirect(route('login'));
}
return $next($request);
}
}
Kernel.php(附錄\ HTTP \ Kernel.php):
protected $routeMiddleware = [
...
'adminCheck' => \App\Http\Middleware\AdminCheck::class,
];
路線(應用\路由\ web.php):
Route::get('dashboard', function(){
//
})->middleware('auth', 'adminCheck');
dashboard.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class dashboard extends Controller
{
public function index()
{
return view('dashboard');
}
}
當我進入http://localhost:8000/dashboard
存在顯示錯誤頁面,上面寫着:
Sorry, the page you are looking for could not be found.
我因無法修復它顯得如此愚蠢。你能幫我找出我的問題在哪裏嗎?提前謝謝你。
我改變**/**儀表板到** ** dashbpard現在的錯誤chenged是:'在UrlGenerator.php線314 InvalidArgumentException:路線[儀表盤]沒有定義.' !!! – Tower