Laravel 显示重定向到 url [英] Laravel displays redirecting to url

查看:93
本文介绍了Laravel 显示重定向到 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试验证输入,但是验证失败时重定向存在怪异问题,laravel显示重定向到 http://localhost:8888/public/admin/categories/create ",然后再加载页面.这是我在控制器中的验证:

Hello everyone I'm trying to validate my input but I have weird problem with redirecting when Validation fails laravel displays "Redirecting to http://localhost:8888/public/admin/categories/create" before page load. Here is my validation in controller:

$rules = [
            'name' => 'required | unique:categories'
        ];
        $input = Input::all();
        $validator = Validator::make($input, $rules);
        if($validator->fails()){
            return Redirect::route('admin.categories.create')->withErrors($validator)->withInput();
        }

如何删除此消息并仅显示有错误的页面?

How I can delete this message and only display page with errors?

推荐答案

当您要求Laravel重定向时,它会执行2件事:

When you ask Laravel to redirect, it does 2 things:

  • 发送带有目标URL的Location标头-这是默认的重定向方法
  • 使用Javascript完成重定向后输出HTML-这是一种备用机制,以防无法发送标头

如果您要使用后备机制,则意味着发送标头时出现问题.最常见的原因是您的代码在发送重定向标头之前确实输出了某些内容.启用错误报告( error_reporting(E_ALL)),您可能会收到警告,提示标题已发送".

If you're seing the fallback mechanism, it means there were issues sending the header. The most common reason is that your code did output something before redirect header was sent. Enable error reporting (error_reporting(E_ALL)) and you will probably get a warning saying "headers already sent".

这篇关于Laravel 显示重定向到 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆