Skip to content

Commit

Permalink
Restore User Model
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata committed Jul 23, 2024
1 parent 360975b commit 87f3ebc
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
113 changes: 113 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,120 @@
<?php

namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasDefaultTenant;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use JoelButcher\Socialstream\HasConnectedAccounts;
use JoelButcher\Socialstream\SetsProfilePhotoFromUrl;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable implements HasDefaultTenant, HasTenants, FilamentUser
{
use HasApiTokens;
use HasConnectedAccounts;
use HasRoles;
use HasFactory;
use HasProfilePhoto {
HasProfilePhoto::profilePhotoUrl as getPhotoUrl;
}
use Notifiable;
use SetsProfilePhotoFromUrl;
use TwoFactorAuthenticatable;
use HasTeams;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
];

/**
* The accessors to append to the model's array form.
*
* @var array<int, string>
*/
protected $appends = [
'profile_photo_url',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
];
}

/**
* Get the URL to the user's profile photo.
*/
public function profilePhotoUrl(): Attribute
{
return filter_var($this->profile_photo_path, FILTER_VALIDATE_URL)
? Attribute::get(fn () => $this->profile_photo_path)
: $this->getPhotoUrl();
}

/**
* @return array<Model> | Collection
*/
public function getTenants(Panel $panel): array|Collection
{
return $this->ownedTeams;
}

public function canAccessTenant(Model $tenant): bool
{
return true; //$this->ownedTeams->contains($tenant);
}

public function canAccessPanel(Panel $panel): bool
{
// return $this->hasVerifiedEmail();
return true;
}

public function canAccessFilament(): bool
{
// return $this->hasVerifiedEmail();
return true;
}


public function getDefaultTenant(Panel $panel): ?Model
{
return $this->latestTeam;
Expand Down
1 change: 1 addition & 0 deletions database/seeders/PermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan;
use App\Models\User;

class PermissionsSeeder extends Seeder
{
Expand Down

0 comments on commit 87f3ebc

Please sign in to comment.