laravel 抱歉,找不到您要找的页面。拉拉维尔

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39237271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:23:27  来源:igfitidea点击:

Sorry, the page you are looking for could not be found. laravel

laravelredirectmiddleware

提问by Tower

I am trying to redirect the admin to dashboard page by the following codes but when I enter /dashboard, the browser displays a NotFoundHttpExceptionerror page.

Middleware (AdminCheck.php) :

我正在尝试通过以下代码将管理员重定向到仪表板页面,但是当我输入时/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) :

Kernel.php (App\Http\Kernel.php) :

protected $routeMiddleware = [
        ...
        'adminCheck' => \App\Http\Middleware\AdminCheck::class,
    ];

Route (App\routes\web.php) :

路线 (App\routes\web.php) :

Route::get('dashboard', function (){
    // 
})->middleware('auth', 'adminCheck');

dashboard.php :

仪表板.php :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class dashboard extends Controller
{
    public function index () 
    {
        return view('dashboard');
    }
}

When I enter http://localhost:8000/dashboardthere is an error page displayed that says :

当我进入时http://localhost:8000/dashboard,会显示一个错误页面,上面写着:

Sorry, the page you are looking for could not be found.   

I seem so dumb by not being able to fix it. Would you help me find out where my problem is? Thank you so much in advance.

无法修复它,我看起来很愚蠢。你能帮我找出我的问题在哪里吗?非常感谢你提前。

采纳答案by soywod

Maybe it comes from your controller name. Laravel follows the PSR-4 standard for autoloading classes, see doc here, your class name should start by an uppercase :

也许它来自您的控制器名称。Laravel 遵循 PSR-4 自动加载类标准,请参阅此处的文档,您的类名应以大写开头:

\NamespaceName{\SubNamespaceNames*}\ClassName

\NamespaceName{\SubNamespaceNames*}\ClassName

Try to rename your dashboard.php into Dashboard.php, remake a php composer dumpautoloadto see ? This route should work after that :

尝试将您的dashboard.php 重命名为Dashboard.php,重新创建一个php composer dumpautoload看看?这条路线应该在那之后工作:

Route::get('dashboard', 'Dashboard@index')->middleware('auth', 'adminCheck');

Route::get('dashboard', 'Dashboard@index')->middleware('auth', 'adminCheck');

回答by Gujarat Santana

Usually when you got problem like this you haven't define your path url in route. please add this your route :

通常当你遇到这样的问题时,你没有在路由中定义你的路径 url。请将此添加到您的路线:

Route::resource('dashboard','YourController');

and some tips if you find the error and have no idea what's going on, you can go to laravel.logfile for more detail about your error, you can find it here : storage/logs/laravel.log

以及一些提示,如果您发现错误并且不知道发生了什么,您可以转到laravel.log文件以获取有关您的错误的更多详细信息,您可以在此处找到它:storage/logs/laravel.log

回答by Seva Kalashnikov

Make your route to use indexmethod of dashboardclass for /dashboard usl

使您的路线使用/dashboard uslindexdashboard类方法

Route::group(['middleware' => ['auth', 'adminCheck']], function () {
    Route::get('dashboard', dashboard::class . '@index');
});

回答by Sachith Muhandiram

Do you have a view called dashboard.blade.phpin your resources/viewfolder?

This error occurs when you do not have a blade template. Or sometimes, you may had made a mistake when you name it. So it may have dashbord.blade.phpnot dashboard.blade.php

dashboard.blade.php你的resources/view文件夹中有一个视图吗?

当您没有刀片模板时会发生此错误。或者有时,您可能在命名时犯了一个错误。所以它可能dashbord.blade.php没有dashboard.blade.php