mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 14:06:15 +00:00
2.x
This commit is contained in:
@ -3,8 +3,13 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Traits\HasTimezoneTimestamps;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Models\Contracts\HasTenants;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
@ -34,10 +39,13 @@
|
||||
* @property Project $currentProject
|
||||
* @property Collection<Project> $projects
|
||||
* @property string $role
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements HasTenants
|
||||
{
|
||||
use HasFactory;
|
||||
use HasTimezoneTimestamps;
|
||||
use Notifiable;
|
||||
use TwoFactorAuthenticatable;
|
||||
|
||||
@ -111,6 +119,16 @@ public function projects(): BelongsToMany
|
||||
return $this->belongsToMany(Project::class, 'user_project')->withTimestamps();
|
||||
}
|
||||
|
||||
public function getTenants(Panel $panel): Collection
|
||||
{
|
||||
return $this->projects;
|
||||
}
|
||||
|
||||
public function canAccessTenant(Model $tenant): bool
|
||||
{
|
||||
return $this->projects()->whereKey($tenant)->exists();
|
||||
}
|
||||
|
||||
public function currentProject(): HasOne
|
||||
{
|
||||
return $this->HasOne(Project::class, 'id', 'current_project_id');
|
||||
@ -121,7 +139,7 @@ public function createDefaultProject(): Project
|
||||
$project = $this->projects()->first();
|
||||
|
||||
if (! $project) {
|
||||
$project = new Project();
|
||||
$project = new Project;
|
||||
$project->name = 'default';
|
||||
$project->save();
|
||||
|
||||
|
Reference in New Issue
Block a user