Added Email Capability
This commit is contained in:
+26
-2
@@ -13,11 +13,14 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use App\Traits\HasAchievements;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use App\Notifications\ResetPasswordNotification;
|
||||
|
||||
|
||||
#[Fillable(['name', 'email', 'password', 'distance_unit', 'settings'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
@@ -35,6 +38,22 @@ class User extends Authenticatable
|
||||
|
||||
protected $appends = ['resolved_settings'];
|
||||
|
||||
public function calculateAchievementsAndClearCache(): void
|
||||
{
|
||||
$this->clearCache();
|
||||
$this->calculateAchievements();
|
||||
}
|
||||
|
||||
public function clearCache(): void
|
||||
{
|
||||
Cache::forget("user_flights_{$this->id}");
|
||||
|
||||
$this
|
||||
->followers()
|
||||
->get()
|
||||
->each(fn ($follower) => Cache::forget("user_following_flights_{$follower->id}"));
|
||||
}
|
||||
|
||||
public function achievements(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAchievement::class);
|
||||
@@ -83,6 +102,11 @@ class User extends Authenticatable
|
||||
});
|
||||
}
|
||||
|
||||
public function sendPasswordResetNotification($token): void
|
||||
{
|
||||
$this->notify(new ResetPasswordNotification($token));
|
||||
}
|
||||
|
||||
public function resolveRouteBinding($value, $field = null): ?User
|
||||
{
|
||||
return $this->where('name', 'ilike', $value)->firstOrFail();
|
||||
@@ -129,8 +153,8 @@ class User extends Authenticatable
|
||||
$today = now('UTC')->toDateString();
|
||||
|
||||
return match ($filter) {
|
||||
'departed' => $collection->filter(fn($f) => $f->departure_date <= $today)->values(),
|
||||
'upcoming' => $collection->filter(fn($f) => $f->departure_date > $today)->values(),
|
||||
'departed' => $collection->filter(fn($f) => Carbon::parse($f->departure_date)->toDateString() <= $today)->values(),
|
||||
'upcoming' => $collection->filter(fn($f) => Carbon::parse($f->departure_date)->toDateString() > $today)->values(),
|
||||
default => $collection,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user