added teams
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property int $created_by
|
||||
* @property bool $require_2fa
|
||||
* @property \Carbon\CarbonImmutable|null $created_at
|
||||
* @property \Carbon\CarbonImmutable|null $updated_at
|
||||
* @property-read \App\Models\TeamMember|null $pivot
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $members
|
||||
* @property-read int|null $members_count
|
||||
* @method static Builder<static>|Team newModelQuery()
|
||||
* @method static Builder<static>|Team newQuery()
|
||||
* @method static Builder<static>|Team query()
|
||||
* @method static Builder<static>|Team visibleTo(\App\Models\User $user)
|
||||
* @method static Builder<static>|Team whereCreatedAt($value)
|
||||
* @method static Builder<static>|Team whereCreatedBy($value)
|
||||
* @method static Builder<static>|Team whereId($value)
|
||||
* @method static Builder<static>|Team whereName($value)
|
||||
* @method static Builder<static>|Team whereRequire2fa($value)
|
||||
* @method static Builder<static>|Team whereSlug($value)
|
||||
* @method static Builder<static>|Team whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
#[Fillable(['name', 'slug', 'require_2fa'])]
|
||||
class Team extends Model
|
||||
{
|
||||
protected function casts()
|
||||
{
|
||||
return [
|
||||
'require_2fa' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function members(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'team_members')
|
||||
->using(TeamMember::class)
|
||||
->withPivot('role')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function scopeVisibleTo(Builder $query, User $user): Builder
|
||||
{
|
||||
return $query->whereHas('members', function (Builder $query) use ($user): void {
|
||||
$query->whereKey($user->getKey());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user