【问题标题】:Not Redirecting to 404 page with laravel give error if put wrong Url如果输入错误的 URL,不使用 laravel 重定向到 404 页面会出错
【发布时间】:2019-08-03 19:01:08
【问题描述】:

喂! 我正在使用 laravel 5.8,当我在我的 url 中输入错误的地址时,它会给出错误

Trying to get property of non-object (View: C:\xampp\htdocs\cms\resources\views\post.blade.php)

网址喜欢

http://127.0.0.1:8000/lkfajds;

这是我输入的错误网址。

为什么这不让我回到 404 页面我该怎么做呢

想要:我想将我重定向到 404 页面

这里是htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

【问题讨论】:

    标签: laravel .htaccess laravel-5


    【解决方案1】:

    您需要在模型上使用 firstOrFail() 以便它可以向您显示 404 页面。

    【讨论】:

    • 方法 Illuminate\View\View::Fail 不存在。它给了我这个错误
    • 不在视图中。如果您在模型中搜索某些东西,您可以使用它。laravel-news.com/laravel-firstorfail-forthewin
    • 如果我想创建自己的 404 还有一件事,那么我该如何重定向这个
    • 在视图中您需要创建一个文件夹名称“errors”,并在其中添加错误页面的名称,如下所示:404.blade.php
    猜你喜欢
    • 1970-01-01
    • 2020-11-12
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多