56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @property list<array<string, mixed>> $specializations
|
|
* @property string $url
|
|
*/
|
|
class Sector extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'name', 'slug', 'short_description', 'description',
|
|
'icon', 'sort_order', 'is_active', 'published_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'published_at' => 'datetime',
|
|
];
|
|
|
|
/** Presentation only: historical masters and foreign keys remain untouched.
|
|
* @param Builder<Sector> $query
|
|
* @return Builder<Sector>
|
|
*/
|
|
public function scopeChoices(Builder $query): Builder
|
|
{
|
|
return $query->where('is_active', true)->where('slug', '!=', 'energia');
|
|
}
|
|
|
|
/** @param Builder<Sector> $query
|
|
* @return Builder<Sector>
|
|
*/
|
|
public function scopeCatalog(Builder $query): Builder
|
|
{
|
|
return $query->choices()->whereNotNull('published_at')->where('slug', '!=', 'fintech');
|
|
}
|
|
|
|
public function getNameAttribute(?string $value): ?string
|
|
{
|
|
return ($this->attributes['slug'] ?? null) === 'fintech' ? 'Mercado Financeiro — Fintech' : $value;
|
|
}
|
|
|
|
/** @return HasMany<Opportunity, $this> */
|
|
public function opportunities(): HasMany
|
|
{
|
|
return $this->hasMany(Opportunity::class);
|
|
}
|
|
}
|