doulan6245 2014-12-06 18:59
浏览 48
已采纳

如何在Laravel中验证失败的验证值

I'm trying to pass a value on failed validation in Laravel.

I tried this, but couldn't get the output.

if ($validation->fails()) {
   $errorflag=1;
   return Redirect::back()->withInput()->withErrors($validation)->with('errorflag', $errorflag);
}

I tried to get this value in the view using just a isset() check

<?php 
  if(isset($errorflag)){
      echo $errorflag;
  }
?>

But I'm unable to get the output even though I made a validation error in the form. How can I do this?

  • 写回答

2条回答 默认 最新

  • dongyi6845 2014-12-06 19:07
    关注

    No need for a flag or session param, withErrors fills the variable $errors and thus is detectable:

    @if($errors->any())
       // do something
    @endif
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算