Laravel show errors in view

error-handling, laravel, laravel-4, php

Solution

Did you read the docs? http://laravel.com/docs/5.0/validation#error-messages-and-views

You can use `return Redirect::back()->withErrors($validation);` In your views, you can always use redirect('register')->withErrors($validator)`$errors`, without binding them to the view.

Problem

if my validation fails I do this: ``` return Redirect::back()->with('validation', $validation->errors->all()); ``` also I am using: ``` $restful = true; ``` so when I am on `get_edit()` - I'am getting an error that there are no $validation variable when generating my view, when in `post_edit()` - its all okay because its returns a redirect with errors... this is my view: ``` <? foreach($validation as $e): ?> <div><?= $e; ?></div> <? endforeach; ?> ``` undefined variable $validation, right now I'am trying to put it on the Router::before ``` Route::filter('before', function() { View::share('validation', array()); }); ``` so the variable exists but is empty, but now arises a new problem, everytime after this filter executes it overrides those `$validation` that generates my `post_edit()`, also i've seen a variable `$errors` in my view but is ever empty, i don't how to use it, can you help me? so shortly my problem is: ``` public function get_edit($id) { //generate my view with all nessesary data, but i can't generate here an error variable // or its better to put it in one place to globally share it in the views, otherwise i am //getting an error } public function post_edit($id) { //validating $_POST data, if there is an error redirect it back to the get_edit() WITH a //variable containing errors } ```

Original source