99 lines
2.3 KiB
PHP
99 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Constant\Constant;
|
||
|
|
use App\Models\Traits\Vihar\Attributes\ViharAttributes;
|
||
|
|
use App\Models\Traits\Vihar\Relationships\ViharRelationships;
|
||
|
|
use App\Models\Traits\Vihar\Scopes\ViharScope;
|
||
|
|
use App\Traits\HasKarmaPoint;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class Vihar extends Model
|
||
|
|
{
|
||
|
|
use HasFactory, ViharRelationships, ViharAttributes, ViharScope, HasKarmaPoint;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* Pseudo-fields that get added to the models when the models are exported to json.
|
||
|
|
*/
|
||
|
|
protected $appends = ['created_ago', 'updated_ago', 'is_owner', 'live_vihar'];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The attributes that are mass assignable.
|
||
|
|
*
|
||
|
|
* @var array
|
||
|
|
*/
|
||
|
|
protected $fillable = [
|
||
|
|
'user_id',
|
||
|
|
'sant_id',
|
||
|
|
'thana_sant_id',
|
||
|
|
'from_sangh_id',
|
||
|
|
'from',
|
||
|
|
'from_latitude',
|
||
|
|
'from_longitude',
|
||
|
|
'to_sangh_id',
|
||
|
|
'to',
|
||
|
|
'to_latitude',
|
||
|
|
'to_longitude',
|
||
|
|
'start_date',
|
||
|
|
'end_date',
|
||
|
|
'start_time',
|
||
|
|
'is_approved',
|
||
|
|
'end_time',
|
||
|
|
'created_by',
|
||
|
|
'updated_by',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $guarded = [
|
||
|
|
'id',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns model in days since created_at.
|
||
|
|
*/
|
||
|
|
public function getCreatedAgoAttribute() {
|
||
|
|
return $this->created_at->diffForHumans();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns model in days since updated_at.
|
||
|
|
*/
|
||
|
|
public function getUpdatedAgoAttribute() {
|
||
|
|
if ($this->updated_at) {
|
||
|
|
return $this->updated_at->diffForHumans();
|
||
|
|
} else {
|
||
|
|
return Constant::NULL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get all of the thana that belong to the chaturmas.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||
|
|
*/
|
||
|
|
public function viharThana()
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Sant::class, 'vihar_thanas')
|
||
|
|
->withTimestamps();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* add points for for registration.
|
||
|
|
*/
|
||
|
|
public function addPoints()
|
||
|
|
{
|
||
|
|
return $this->morphMany(KarmaPointsTransaction::class, 'pointable');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns model in days since created_at.
|
||
|
|
*/
|
||
|
|
public function getIsOwnerAttribute() {
|
||
|
|
$user = loggedInUser();
|
||
|
|
if ($user){
|
||
|
|
return $this->created_by == $user->id;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|