1

I have stack of calls in controller:

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

The function withErrors takes array of errors.

How can I display there messages in template?

I tried:

{{Session::get('MessageBag')}}

So, the latest edition is:

 $errors = $validator->messages(); // Here I get $error with fillied data
            return redirect('tour/create')
                ->withErrors($errors)
                ->withInput();

In template I do:

{{count($errors)}}

It gives me zero

Dev
  • 1,013
  • 7
  • 15
  • 37

2 Answers2

4

In view file access errors with $errors

{{$errors->first('MessageBag')}}

Try to print $errors print_r($errors). It is global variable for views.

Rakesh Kumar
  • 4,319
  • 2
  • 17
  • 30
  • It does not work, I dont see messages, may be due to `Redirect`? – Dev Aug 05 '16 at 08:02
  • If do `{{dd($errors)}}` in teplate I get: "#bags: []" – Dev Aug 05 '16 at 08:52
  • For validation I use: `$validator = Validator::make($request->all(), [])` – Dev Aug 05 '16 at 09:57
  • it should be Validator::make($request->all(), [ 'heading' => 'required', 'subheading' => 'required', 'description' => 'required', 'id_holiday_type' => 'required|max:10', 'total_floors' => 'required|max:10', #'floor_space' => 'required', #'ground_size' => 'required', 'accommondation_style' => 'required', 'swimming_pool' => 'required', 'internet_access' => 'required', ]); – Rakesh Kumar Aug 05 '16 at 10:12
  • When I do `dd($validator)` I get NULL – Dev Aug 05 '16 at 10:19
2

Try this you can see whether the data is available

  {{ dd(Request::session()) }}
Parithiban
  • 1,656
  • 11
  • 16