Ali Erfani
Ali Erfani

Reputation: 692

Laravel 5.1: with() helper is not working

I am using with() helper to pass some error messages to views. My code for this is

 redirect('somewhere')->with('message', 'show some message')

Then in the targeted view to catch the message I have this:

@if(count($errors)>0)
    <div class="alert alert-success">
        <ul >
            @foreach($errors->all() as $error)
                <li>{{$error}}</li>
            @endforeach
        </ul>
    </div>
@endif

But no message is delivered to the view. What's the problem here?

Upvotes: 0

Views: 57

Answers (2)

Suvash sarker
Suvash sarker

Reputation: 3170

Please check this link Redirecting With Flashed Session Data

In targeted view you can handle message like this

@if (session('message'))
    <div class="alert alert-success">
        {{ session('message') }}
    </div>
@endif

Upvotes: 1

M0rtiis
M0rtiis

Reputation: 3774

 redirect('somewhere')->withErrors(['message', 'show some message'])

Upvotes: 1

Related Questions