73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasKarmaPoint;
|
|
use App\Models\KarmaPointsTransaction;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use App\Models\Traits\Chaturmas\Methods\ChaturmasMethods;
|
|
use App\Models\Traits\Chaturmas\Attributes\ChaturmasAttributes;
|
|
use App\Models\Traits\Chaturmas\Relationships\ChaturmasRelationships;
|
|
|
|
class Chaturmas extends Model
|
|
{
|
|
use HasFactory, ChaturmasAttributes, ChaturmasRelationships, ChaturmasMethods, HasKarmaPoint;
|
|
/*
|
|
* Pseudo-fields that get added to the models when the models are exported to json.
|
|
*/
|
|
protected $appends = ['created_ago', 'updated_ago', 'is_owner'];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'sant_id',
|
|
'sangh_id',
|
|
'thana_sant_id',
|
|
'chaturmas_date_id',
|
|
'place',
|
|
'latitude',
|
|
'longitude',
|
|
'start_date',
|
|
'end_date',
|
|
'is_approved',
|
|
'year',
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
protected $guarded = [
|
|
'id',
|
|
];
|
|
|
|
/**
|
|
* Get all of the thana that belong to the chaturmas.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function chaturmasThana()
|
|
{
|
|
return $this->belongsToMany(Sant::class, 'chaturma_thanas')
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Returns model in days since created_at.
|
|
*/
|
|
public function getIsOwnerAttribute() {
|
|
$user = loggedInUser();
|
|
return $this->created_by == $user->id;
|
|
}
|
|
|
|
/**
|
|
* add points for for registration.
|
|
*/
|
|
public function addPoints()
|
|
{
|
|
return $this->morphMany(KarmaPointsTransaction::class, 'pointable');
|
|
}
|
|
}
|