Reputation: 3903
I'm using the spatie/laravel-newsletter
-package for my laravel
-app and I want to make a check if a User already has subscribed for the newsletter. When a user is subscribed I want to return/display a custom error message, like "You have already subscribed" - or something like that, how is that possible?
Here is my check:
if (Newsletter::isSubscribed(request()->email)) {
// return custom message here?!
}
Any suggestions?
Upvotes: 0
Views: 233
Reputation: 1675
You could flash a session variable with the error message and display it in your view :
if (Newsletter::isSubscribed(request()->email)) {
return redirect('/your-url')->with('errorIsSubscribed', 'You have already subscribed');
}
And then display it in your blade view like so :
@if (session('errorIsSubscribed'))
{{ session('errorIsSubscribed') }}
@endif
Upvotes: 2