Skip to content

Commit

Permalink
Complete add user email to newsletter
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed Jun 16, 2024
1 parent fe26c09 commit bc0e615
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/Livewire/Newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit bc0e615

Please sign in to comment.