doue1925
doue1925
2016-01-29 10:28
浏览 31
已采纳

错误消息未发送到Blade。 Laravel 5.2.12

I am using Laravel 5.2.12

I have a request class like below.

class RegisterRequest extends Request
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'UserName'      =>  'required|min:5|max:50',
            'Password'      =>  'required|confirmed|min:5|max:100',
        ];
    }

    public function response(array $errors){
        print_r($errors);
        return \Redirect::back()->withErrors($errors)->withInput();
    }
}

This request class is being used to validate the data during registration in the inbuilt template of Laravel. Below are the methods

public function postRegister(RegisterRequest $request)
//            **Check here** ^^^^^^^^^^^^^^^
{
    return $this->register($request);
}

We can find the path for this method below.

\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php

Below is the code written in Register page.

@if (count($errors) > 0)
    <div class="alert alert-danger">
        <strong>Whoops!</strong> There were some problems with your input.<br><br>
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

What's the problem ?

Error messages are not displaying in register Blade.

What have I tried so far ?

In the request class, there is below method.

public function response(array $errors){
    print_r($errors);
    //die();
    return \Redirect::back()->withErrors($errors)->withInput();
}

Although it prints when I enable die() but it never sends the error message in blade.

图片转代码服务由CSDN问答提供 功能建议

我使用的是Laravel 5.2.12

我有一个如下所示的请求类。

  class RegisterRequest extends Request 
 {
 public function authorize()
 {
返回 true; 
} 
 
公共函数规则()
 {
返回[
'UserName'=&gt;  'required | min:5 | max:50',
'密码'=&gt;  'required | confirmed | min:5 | max:100',
]; 
} 
 
公共函数响应(数组$ errors){
 print_r($ errors); 
 return \ Redirect :: back  () - &gt; withErrors($ errors) - &gt; withInput(); 
} 
} 
   
 
 

此请求类正用于 在Laravel的内置模板中注册期间验证数据。 以下是方法

  public function postRegister(RegisterRequest $ request)
 // **点击这里** ^^^^^^^^^^  ^^^^^ 
 {
返回$ this-&gt;寄存器($ request); 
} 
   
 
 

我们可以找到此方法的路径 下面。

\ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Auth \ RegistersUsers.php

下面是在Register页面中写的代码。

  @if(count($ errors)&gt; 0)
&lt; div class =“alert alert-danger  “&gt; 
&lt; strong&gt;哎呀!&lt; / strong&gt; 输入存在一些问题。&lt; br&gt;&lt; br&gt; 
&lt; ul&gt; 
 @foreach($ errors-&gt; all()为$ error)
&lt; li&gt; {{$ error}  }&lt; / li&gt; 
 @endforeach 
&lt; / ul&gt; 
&lt; / div&gt; 
 @ endif 
   
 
 

什么是 问题?

错误消息未显示在寄存器Blade中。

到目前为止我尝试了什么?

在请求类中,有以下方法。

 公共函数响应(数组$ errors){
 print_r($ 错误); 
 // die(); 
 return \ Redirect :: back() - &gt; withErrors($ errors) - &gt; withInput(); 
} 
   \  n 
 

虽然它在我启用 die()时打印但它从不发送错误信息 in blade。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douqiao8032
    douqiao8032 2016-01-29 10:41
    已采纳

    I did some changes in Kernel.php. Now I can view the Error Messages in Blade.

    Original Code.

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    ];
    

    Modified To

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    ];
    

    点赞 评论

相关推荐