belongsTo(Sant::class, 'sant_id'); } /** * Get all of the team's sants including its owner. * * @return \Illuminate\Support\Collection */ public function allSants() { return $this->sants->merge([$this->owner]); } /** * Get all of the users that belong to the team. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function thanaMember() { // return $this->belongsToMany(Sant::class, 'thana_members') // ->withTimestamps(); return $this->hasMany(ThanaMember::class, 'thana_id'); } /** * Get all of the users that belong to the team. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function getThanaMember() { return $this->belongsToMany(Sant::class, 'thana_members')->withPivot('id', 'is_leader', 'is_approved') ->withTimestamps(); } /** * Determine if the given user belongs to the team. * * @param \App\Models\User $user * @return bool */ public function hasUser($sant) { return $this->sants->contains($sant) || $sant->ownsTeam($this); } /** * Remove the given user from the team. * * @param \App\Models\User $user * @return void */ public function removeUser($sant) { if ($sant->current_team_id === $this->id) { $sant->forceFill([ 'current_team_id' => null, ])->save(); } $this->sants()->detach($sant); } /** * Purge all of the team's resources. * * @return void */ public function purge() { $this->owner()->where('current_team_id', $this->id) ->update(['current_team_id' => null]); $this->sants()->where('current_team_id', $this->id) ->update(['current_team_id' => null]); $this->sants()->detach(); $this->delete(); } /** * @return mixed */ public function createdBy() { return $this->belongsTo(User::class, 'created_by'); } /** * @return mixed */ public function updatedBy() { return $this->belongsTo(User::class, 'updated_by', 'id'); } }