Files
new_raffles/Modules/CostCalculator/app/Models/CostCalculator.php
2025-08-15 18:01:35 +05:45

54 lines
1.8 KiB
PHP

<?php
namespace Modules\CostCalculator\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\CCMS\Models\Country;
use Modules\CourseFinder\Models\Program;
use Modules\CourseFinder\Models\ProgramLevel;
use Modules\CostCalculator\Models\StayType;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
// use Modules\CostCalculator\Database\Factories\CostCalculatorFactory;
class CostCalculator extends Model
{
use HasFactory;
use \Staudenmeir\EloquentJsonRelations\HasJsonRelationships;
protected $guarded = [];
protected $casts = [
'living_cost' => 'object',
'accomodation_cost' => 'object',
'onetime_cost' => 'object',
'service_cost' => 'object'
];
public function country()
{
return $this->belongsTo(Country::class, 'country_id');
}
public function stayTypeLiving(): BelongsToMany
{
return $this->belongsToMany(StayType::class, 'living_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'monthly', 'yearly')->withTimestamps();
}
public function stayTypeAccomodation(): BelongsToMany
{
return $this->belongsToMany(StayType::class, 'accomodation_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'monthly', 'yearly')->withTimestamps();
}
public function stayTypeOnetime(): BelongsToMany
{
return $this->belongsToMany(StayType::class, 'onetime_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'visa', 'biometrics', 'sevis', 'application')->withTimestamps();
}
public function stayTypeService(): BelongsToMany
{
return $this->belongsToMany(StayType::class, 'service_costs', 'cost_calculator_id', 'stay_type_id')->withPivot('id', 'flight_ticket', 'insurance', 'extra')->withTimestamps();
}
}