belongsTo(Sant::class, 'guru_id', 'id'); } /** * @return mixed */ public function dharm() { return $this->belongsTo(Dharma::class, 'dharma_id'); } /** * @return mixed */ public function sampraday() { return $this->belongsTo(Sampraday::class, 'sampraday_id'); } /** * Get the santFather associated with the user. */ public function santFather() { return $this->hasMany(SantTempRelation::class, 'sant_temp_id', 'sant_id'); } /** * Get the santFather associated with the user. */ public function father() { return $this->hasMany(SantTempRelation::class, 'sant_temp_id', 'sant_id')->where('type', 'father'); } /** * Get the santFather associated with the user. */ public function mother() { return $this->hasMany(SantTempRelation::class, 'sant_temp_id', 'sant_id')->where('type', 'mother'); } /** * Get the santFather associated with the user. */ public function shishya() { return $this->hasMany(SantTemp::class, 'guru_id'); } /** * Get the santFather associated with the user. */ public function maharaj() { return $this->hasMany(SantTemp::class, 'guru_id')->where('gender', Constant::MALE); } /** * Get the santFather associated with the user. */ public function mahasatiJi() { return $this->hasMany(SantTemp::class, 'guru_id')->where('gender', Constant::FEMALE);; } /** * Get the sant followers. */ public function followers() { return $this->belongsToMany(User::class, 'sant_followers', 'sant_id', 'user_id')->withTimestamps(); } /** * Get the sant followings. */ public function followings() { return $this->belongsToMany(User::class, 'sant_followers', 'user_id', 'sant_id')->withTimestamps(); } /** * @return mixed */ public function createdBy() { return $this->belongsTo(User::class, 'created_by', 'id'); } /** * @return mixed */ public function updatedBy() { return $this->belongsTo(User::class, 'updated_by', 'id'); } /** * @return mixed */ public function vihars() { return $this->hasMany(Vihar::class, 'sant_id', 'id'); } /** * @return mixed */ public function chaturmas() { return $this->hasMany(Chaturmas::class, 'sant_id', 'sant_id')->where('is_approved', 0); } /** * @return mixed */ public function editedLocation() { return $this->belongsTo(SantLocation::class, 'sant_id', 'sant_id'); } /** * @return mixed */ public function location() { return $this->hasOne(Vihar::class, 'sant_id', 'id')->where(function ($query) { $query->where(function ($query) { $query->where('start_date', '<', Carbon::now()->toDateString()) ->orWhere('start_time', '<', Carbon::now()->subHour(2)->toTimeString()); }); })->latest('end_date')->latest('start_time'); } /** * @return mixed */ public function pastLocation() { return $this->hasOne(Vihar::class, 'sant_id', 'id')->where('end_date', '<', Carbon::now()->toDateString())->latest('end_date')->latest('start_time'); } /** * add points for for registration. */ public function addPoints() { return $this->morphMany(KarmaPointsTransaction::class, 'pointable'); } /** * Determine if the given team is the current team. * * @param mixed $team * @return bool */ public function isCurrentThana($thana) { return $thana->id === $this->currentThana->id; } /** * Get the current team of the user's context. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function currentThana() { // if (is_null($this->current_team_id) && $this->id) { // $this->switchTeam($this->personalTeam()); // } return $this->belongsTo(Thana::class, 'current_team_id'); } /** * Get all of the teams the user owns or belongs to. * * @return \Illuminate\Support\Collection */ // public function allTeams() // { // return $this->ownedThana->merge($this->teams)->sortBy('name'); // } /** * Get all of the teams the user owns. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function ownedThana() { return $this->hasOne(Thana::class, 'sant_id', 'sant_id'); } /** * Get all of the teams the user owns. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function thanaMember() { return $this->hasMany(ThanaMember::class, 'sant_id', 'sant_id'); } /** * Get all of the teams the user belongs to. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ // public function thanas() // { // return $this->belongsToMany(Thana::class, 'thana_members') // ->withTimestamps(); // } /** * Determine if the user belongs to the given team. * * @param mixed $team * @return bool */ // public function belongsToTeam($team) // { // if (is_null($team)) { // return false; // } // return $this->ownsTeam($team) || $this->thanas->contains(function ($t) use ($team) { // return $t->id === $team->id; // }); // } }