抱歉,无法找到您要查找的页面。 laravel
Sorry, the page you are looking for could not be found. laravel
我试图通过以下代码将管理员重定向到仪表板页面,但是当我输入 /dashboard
时,浏览器显示 NotFoundHttpException
错误页面。
中间件(AdminCheck.php):
<?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 (App\Http\Kernel.php) :
protected $routeMiddleware = [
...
'adminCheck' => \App\Http\Middleware\AdminCheck::class,
];
路线 (App\routes\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.
无法修复它,我看起来很愚蠢。你能帮我看看我的问题出在哪里吗?非常感谢您。
您的 resources/view
文件夹中是否有名为 dashboard.blade.php
的视图?
当您没有 blade 模板时会发生此错误。或者有时,您可能在命名时犯了错误。所以它可能 dashbord.blade.php
而不是 dashboard.blade.php
通常当你遇到这样的问题时,你没有在路由中定义你的路径 url。请添加您的路线:
Route::resource('dashboard','YourController');
和一些提示如果您发现错误但不知道发生了什么,您可以转到 laravel.log
文件以获取有关错误的更多详细信息,您可以在此处找到它:storage/logs/laravel.log
使您的路线使用 dashboard
class 的 index
方法用于 /dashboard usl
Route::group(['middleware' => ['auth', 'adminCheck']], function () {
Route::get('dashboard', dashboard::class . '@index');
});
也许它来自您的控制器名称。 Laravel 遵循自动加载 classes、see doc here 的 PSR-4 标准,您的 class 名称应以大写字母开头:
\NamespaceName{\SubNamespaceNames*}\ClassName
尝试将您的 dashboard.php 重命名为 Dashboard.php,重新制作一个 php composer dumpautoload
看看?这条路线在那之后应该有效:
Route::get('dashboard', 'Dashboard@index')->middleware('auth', 'adminCheck');
我试图通过以下代码将管理员重定向到仪表板页面,但是当我输入 /dashboard
时,浏览器显示 NotFoundHttpException
错误页面。
中间件(AdminCheck.php):
<?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 (App\Http\Kernel.php) :
protected $routeMiddleware = [
...
'adminCheck' => \App\Http\Middleware\AdminCheck::class,
];
路线 (App\routes\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.
无法修复它,我看起来很愚蠢。你能帮我看看我的问题出在哪里吗?非常感谢您。
您的 resources/view
文件夹中是否有名为 dashboard.blade.php
的视图?
当您没有 blade 模板时会发生此错误。或者有时,您可能在命名时犯了错误。所以它可能 dashbord.blade.php
而不是 dashboard.blade.php
通常当你遇到这样的问题时,你没有在路由中定义你的路径 url。请添加您的路线:
Route::resource('dashboard','YourController');
和一些提示如果您发现错误但不知道发生了什么,您可以转到 laravel.log
文件以获取有关错误的更多详细信息,您可以在此处找到它:storage/logs/laravel.log
使您的路线使用 dashboard
class 的 index
方法用于 /dashboard usl
Route::group(['middleware' => ['auth', 'adminCheck']], function () {
Route::get('dashboard', dashboard::class . '@index');
});
也许它来自您的控制器名称。 Laravel 遵循自动加载 classes、see doc here 的 PSR-4 标准,您的 class 名称应以大写字母开头:
\NamespaceName{\SubNamespaceNames*}\ClassName
尝试将您的 dashboard.php 重命名为 Dashboard.php,重新制作一个 php composer dumpautoload
看看?这条路线在那之后应该有效:
Route::get('dashboard', 'Dashboard@index')->middleware('auth', 'adminCheck');