42 lines
846 B
PHP
42 lines
846 B
PHP
<?php
|
|
|
|
namespace App\Models\Verifikator;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class TeamUser extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'verifikator.team_users';
|
|
protected $fillable = ['team_id', 'user_id', 'active'];
|
|
|
|
function team()
|
|
{
|
|
return $this->belongsTo(Team::class);
|
|
}
|
|
|
|
function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
function scopeActive($query)
|
|
{
|
|
return $query->where('active', 1);
|
|
}
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::updating(function ($model) {
|
|
if ($model->active == 1) {
|
|
TeamUser::where('user_id', '!=', $model->user_id)->update(['active' => 0]);
|
|
}
|
|
});
|
|
}
|
|
}
|