56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @property string|null $primary_territory_id
|
|
* @property int $territory_version
|
|
*/
|
|
class Opportunity extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'sector_id', 'reference', 'title', 'slug', 'summary', 'description',
|
|
'province', 'district', 'promoter_name', 'promoter_type',
|
|
'maturity_level', 'maturity_label', 'estimated_investment_amount',
|
|
'estimated_investment_currency', 'financing_modality',
|
|
'expected_impact', 'status', 'is_featured', 'published_at',
|
|
'last_validated_at',
|
|
'primary_territory_id', 'territory_version',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_featured' => 'boolean',
|
|
'territory_version' => 'integer',
|
|
'published_at' => 'datetime',
|
|
'last_validated_at' => 'datetime',
|
|
'estimated_investment_amount' => 'decimal:2',
|
|
];
|
|
|
|
/** @return BelongsTo<Sector, $this> */
|
|
public function sector(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Sector::class);
|
|
}
|
|
|
|
/** @return BelongsTo<GeoLocation, $this> */
|
|
public function primaryTerritory(): BelongsTo
|
|
{
|
|
return $this->belongsTo(GeoLocation::class, 'primary_territory_id');
|
|
}
|
|
|
|
/** @param Builder<Opportunity> $query
|
|
* @return Builder<Opportunity>
|
|
*/
|
|
public function scopePublished(Builder $query): Builder
|
|
{
|
|
return $query->where('status', 'published')->whereNotNull('published_at')->where('published_at', '<=', now());
|
|
}
|
|
}
|