Skip to content

Commit

Permalink
Add newsletter column in users table (#308)
Browse files Browse the repository at this point in the history
* Add newsletter column in users table

* Controller
  • Loading branch information
alexPopaCode4 authored Jan 17, 2024
1 parent 3e3784b commit d99c56c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public function store(RegistrationRequest $request): RedirectResponse
{
$attributes = $request->validated();

$subscribe = $attributes['subscribe'];
$user = User::create([
'name' => $attributes['user']['name'],
'email' => $attributes['user']['email'],
'password' => Hash::make($attributes['user']['password']),
'role' => $attributes['type'] === 'organization' ? UserRole::ADMIN : UserRole::USER,
'newsletter' => (bool)$subscribe
]);

event(new Registered($user));
Expand All @@ -66,7 +68,7 @@ public function store(RegistrationRequest $request): RedirectResponse
$user->save();
}

if ($attributes['subscribe']) {
if ($subscribe) {
NewsletterService::subscribe($user->email, $user->name);
}

Expand Down
1 change: 1 addition & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
'referrer',
'created_by',
'organization_id',
'newsletter'
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('newsletter')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('newsletter');
});
}
};

0 comments on commit d99c56c

Please sign in to comment.