From bc0e615cb2657ed61c6ca88efbb03f37d161acc2 Mon Sep 17 00:00:00 2001 From: raccoon254 Date: Sun, 16 Jun 2024 08:34:55 +0300 Subject: [PATCH] Complete add user email to newsletter --- app/Livewire/Newsletter.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/Livewire/Newsletter.php b/app/Livewire/Newsletter.php index e2c9fda..a75dc84 100644 --- a/app/Livewire/Newsletter.php +++ b/app/Livewire/Newsletter.php @@ -2,11 +2,29 @@ namespace App\Livewire; +use App\Models\Subscriber; use Illuminate\View\View; use Livewire\Component; class Newsletter extends Component { + public $email; + + protected $rules = [ + 'email' => 'required|email|unique:subscribers,email', + ]; + + public function subscribe(): void + { + $this->validate(); + + Subscriber::create(['email' => $this->email]); + + session()->flash('message', 'You have successfully subscribed to the newsletter!'); + + $this->reset('email'); + } + public function render(): View { return view('livewire.newsletter');