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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.