2024-07-04 17:21:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2025-04-28 18:03:38 +02:00
|
|
|
use App\Traits\EnsureUserHasWorkspace;
|
2024-07-04 17:21:36 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class UserWorkspace extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
2025-04-28 18:03:38 +02:00
|
|
|
use EnsureUserHasWorkspace;
|
|
|
|
|
|
2024-07-04 17:21:36 +02:00
|
|
|
protected $table = 'user_workspace';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'user_id',
|
|
|
|
|
'workspace_id',
|
|
|
|
|
'role',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function workspace()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Workspace::class);
|
|
|
|
|
}
|
2025-04-28 18:03:38 +02:00
|
|
|
|
|
|
|
|
protected static function boot()
|
|
|
|
|
{
|
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
|
|
static::deleted(function (UserWorkspace $userWorkspace) {
|
|
|
|
|
$userWorkspace->ensureUserHasWorkspace($userWorkspace->user);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-07-04 17:21:36 +02:00
|
|
|
}
|