简体   繁体   中英

Undefined variable: errors Lumen 5.4

I got this error Undefined variable: error in Lumen 5.4

web.php

$app->get('/', 'SubscribersController@index');   
$app->post('/', 'SubscribersController@store');

controller

    public function store(Request $request)
{
    $this->validate($request, [
        'email' => 'required|email|unique:subscribers,email'
    ]);

    app('db')->table('subscribers')->insert([
        'email' => $request->input('email'),
    ]);

    return redirect('/');
}

index.blade.php

{{dd($errors)}}

So, how i can get my error? I can get error only in json format, but i want put this error on index.blade.php how this is possible?

{
  "email": [
    "The email must be a valid email address."
  ]
}  

I want see this error in index.blade.php

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

The lumen documentation states that Lumen does not have the $error variable for views and that you should catch the error $this->validate throws. This way you can add the variables to your view manualy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM