60 lines
1.2 KiB
PHP
60 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\TeamRole;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
|
|
|
#[Fillable(['team_id', 'user_id', 'role'])]
|
|
class Membership extends Pivot
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'team_members';
|
|
|
|
/**
|
|
* Indicates if the IDs are auto-incrementing.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $incrementing = true;
|
|
|
|
/**
|
|
* Get the team that the membership belongs to.
|
|
*
|
|
* @return BelongsTo<Team, $this>
|
|
*/
|
|
public function team(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Team::class);
|
|
}
|
|
|
|
/**
|
|
* Get the user that belongs to this membership.
|
|
*
|
|
* @return BelongsTo<Model, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'role' => TeamRole::class,
|
|
];
|
|
}
|
|
}
|