In my laravel
-app users can check a checkbox on the contact form if they want to subscribe for a newsletter. When the checkbox is checked and the submit the form, there is a check in the controller, if the user already is subscribed and if so, a flash alert/message should appear with something like 'You are already subscribed'.
Now, the check itself works, but the flash/alert message is not displaying and I don't know why.
in my view:
@if (\Session::has('success'))
<div class="alert alert-success">
<p>{{ \Session::get('success') }}</p>
</div>
@endif
@if (\Session::has('failure'))
<div class="alert alert-danger">
<p>{{ \Session::get('failure') }}</p>
</div>
@endif
<div class="contact-form" id="contact">
<form method="POST" action="{{ route('contact.store') }}">
...
</form>
</div>
and in my controller:
// when the checkbox is checked!
if (!empty(request()->newsletter)) {
if (!Newsletter::isSubscribed(request()->email)) {
Newsletter::subscribePending(request()->email);
return redirect()->route('contact.create')->with('success', 'Thanks for subscribing!');
} else {
return redirect()->route('contact.create')->with('failure', 'You are already subscribed');
}
}
Can someone help me out?