<tfoot id='oS8C0'></tfoot>
    <bdo id='oS8C0'></bdo><ul id='oS8C0'></ul>

    <small id='oS8C0'></small><noframes id='oS8C0'>

        <i id='oS8C0'><tr id='oS8C0'><dt id='oS8C0'><q id='oS8C0'><span id='oS8C0'><b id='oS8C0'><form id='oS8C0'><ins id='oS8C0'></ins><ul id='oS8C0'></ul><sub id='oS8C0'></sub></form><legend id='oS8C0'></legend><bdo id='oS8C0'><pre id='oS8C0'><center id='oS8C0'></center></pre></bdo></b><th id='oS8C0'></th></span></q></dt></tr></i><div id='oS8C0'><tfoot id='oS8C0'></tfoot><dl id='oS8C0'><fieldset id='oS8C0'></fieldset></dl></div>

      1. <legend id='oS8C0'><style id='oS8C0'><dir id='oS8C0'><q id='oS8C0'></q></dir></style></legend>

        从控制器重定向后在 Laravel 中显示错误消息

        时间:2023-11-01
        • <i id='7KgO9'><tr id='7KgO9'><dt id='7KgO9'><q id='7KgO9'><span id='7KgO9'><b id='7KgO9'><form id='7KgO9'><ins id='7KgO9'></ins><ul id='7KgO9'></ul><sub id='7KgO9'></sub></form><legend id='7KgO9'></legend><bdo id='7KgO9'><pre id='7KgO9'><center id='7KgO9'></center></pre></bdo></b><th id='7KgO9'></th></span></q></dt></tr></i><div id='7KgO9'><tfoot id='7KgO9'></tfoot><dl id='7KgO9'><fieldset id='7KgO9'></fieldset></dl></div>
        • <tfoot id='7KgO9'></tfoot>
        • <small id='7KgO9'></small><noframes id='7KgO9'>

          <legend id='7KgO9'><style id='7KgO9'><dir id='7KgO9'><q id='7KgO9'></q></dir></style></legend>
              <tbody id='7KgO9'></tbody>

              • <bdo id='7KgO9'></bdo><ul id='7KgO9'></ul>

                  本文介绍了从控制器重定向后在 Laravel 中显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 Laravel 中重定向的视图中显示验证消息?

                  这是我在控制器中的功能

                  公共函数 registeruser(){$firstname = 输入::get('firstname');$lastname = 输入::get('姓氏');$data = 输入::except(array('_token')) ;$规则=数组('名字' =>'必需的','姓氏' =>'必需的',) ;$validator = Validator::make($data,$rule);if ($validator->fails()){$messages = $validator->messages();return Redirect::to('/')->with('message', 'Register Failed');}别的{DB::insert('插入用户(名字,姓氏)值(?,?)',数组($名,$姓));return Redirect::to('/')->with('message', '注册成功');}}

                  我知道下面给出的代码是一个不好的尝试,但我该如何解决它,什么是我错过了

                  @if($errors->has())@foreach ($errors->all() as $error)<div>{{ $error }}</div>万一

                  更新:以及如何在特定字段附近显示错误消息

                  解决方案

                  Laravel 4

                  当验证失败时返回验证错误.

                  if($validator->fails()) {return Redirect::back()->withErrors($validator);}

                  您可以使用

                  在您的视图中捕获错误

                  @if($errors->any()){{ implode('', $errors->all('<div>:message</div>')) }}@万一

                  更新

                  要在每个字段下显示错误,您可以这样做.

                  has('firstname'))<div class="error">{{ $errors->first('firstname') }}</div>@万一

                  使用 css 获得更好的显示样式.

                  您可以在这里参考文档.p>

                  更新 2

                  一次显示所有错误

                  @if($errors->any()){!!内爆('', $errors->all('<div>:message</div>')) !!}@万一

                  在每个字段下显示错误.

                  @error('firstname')<div class="error">{{ $message }}</div>@enderror

                  How can I display the validation message in the view that is being redirected in Laravel ?

                  Here is my function in a Controller

                  public function registeruser()
                  {
                      $firstname = Input::get('firstname');
                      $lastname = Input::get('lastname');
                      $data  =  Input::except(array('_token')) ;
                      $rule  =  array(
                                  'firstname'       => 'required',
                                  'lastname'         => 'required',
                                     ) ;
                      $validator = Validator::make($data,$rule);
                      if ($validator->fails())
                      {
                      $messages = $validator->messages();
                      return Redirect::to('/')->with('message', 'Register Failed');
                      }
                      else
                      {
                      DB::insert('insert into user (firstname, lastname) values (?, ?)',
                                                  array($firstname, $lastname));
                      return Redirect::to('/')->with('message', 'Register Success');
                      }
                      }
                  

                  I know the below given code is a bad try, But how can I fix it and what am I missing

                  @if($errors->has())
                      @foreach ($errors->all() as $error)
                          <div>{{ $error }}</div>
                      @endforeach
                  @endif
                  

                  Update : And how do I display the error messages near to the particular fields

                  解决方案

                  Laravel 4

                  When the validation fails return back with the validation errors.

                  if($validator->fails()) {
                      return Redirect::back()->withErrors($validator);
                  }
                  

                  You can catch the error on your view using

                  @if($errors->any())
                      {{ implode('', $errors->all('<div>:message</div>')) }}
                  @endif
                  

                  UPDATE

                  To display error under each field you can do like this.

                  <input type="text" name="firstname">
                  @if($errors->has('firstname'))
                      <div class="error">{{ $errors->first('firstname') }}</div>
                  @endif
                  

                  For better display style with css.

                  You can refer to the docs here.

                  UPDATE 2

                  To display all errors at once

                  @if($errors->any())
                      {!! implode('', $errors->all('<div>:message</div>')) !!}
                  @endif
                  

                  To display error under each field.

                  @error('firstname')
                      <div class="error">{{ $message }}</div>
                  @enderror
                  

                  这篇关于从控制器重定向后在 Laravel 中显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Laravel 从 Mysql 数据库创建到控制器的动态路由 下一篇:“laravel.log"无法打开:无法打开流

                  相关文章

                  <small id='IMrWb'></small><noframes id='IMrWb'>

                    • <bdo id='IMrWb'></bdo><ul id='IMrWb'></ul>

                  1. <tfoot id='IMrWb'></tfoot>
                      <legend id='IMrWb'><style id='IMrWb'><dir id='IMrWb'><q id='IMrWb'></q></dir></style></legend>

                    1. <i id='IMrWb'><tr id='IMrWb'><dt id='IMrWb'><q id='IMrWb'><span id='IMrWb'><b id='IMrWb'><form id='IMrWb'><ins id='IMrWb'></ins><ul id='IMrWb'></ul><sub id='IMrWb'></sub></form><legend id='IMrWb'></legend><bdo id='IMrWb'><pre id='IMrWb'><center id='IMrWb'></center></pre></bdo></b><th id='IMrWb'></th></span></q></dt></tr></i><div id='IMrWb'><tfoot id='IMrWb'></tfoot><dl id='IMrWb'><fieldset id='IMrWb'></fieldset></dl></div>