File: /var/www/limestate-admin/app/Models/Flat.php
<?php
namespace App\Models;
use App\Collections\FlatOptionCollection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Orchid\Attachment\Attachable;
use Orchid\Attachment\Models\Attachment;
use Orchid\Filters\Filterable;
use Orchid\Filters\Types\Where;
use Orchid\Filters\Types\WhereIn;
use Orchid\Screen\AsSource;
/**
* @property int $id
* @property bool $is_secondary
* @property string $alias
* @property ?int $floor
* @property ?int $rooms
* @property ?float $total_area
* @property ?float $living_area
* @property ?float $rooms_area
* @property ?float $kitchen_area
* @property ?string $number
* @property ?float $price
* @property ?float $base_price
* @property int $building_id
* @property ?float $mortgage_price
* @property ?int $assignment
* @property ?int $contractor
* @property ?int $bathroom_type_id
* @property ?int $balcony_type_id
* @property ?int $finishing_type_id
* @property ?int $view_type_id
* @property ?int $entrance
* @property ?string $rooms_area_separately
* @property ?int $old_ID
* @property ?int $published
* @property ?string $meta_title
* @property ?string $meta_description
* @property ?string $meta_keywords
* @property ?string $created_at
* @property ?string $updated_at
* @property ?string $description
* @property ?int $plan_id
* @property ?string $rutube_id
* @property ?string $deleted_at
*
* @method MorphToMany[] attachment()
* @property Attachment[] $attachment
*
* @property Building $building
* @property FlatOptionCollection $options
* @property Attachment $plan
*/
class Flat extends Model
{
use HasFactory;
use AsSource;
use Filterable;
use Attachable;
use SoftDeletes;
protected $fillable = [
'is_secondary',
'alias',
'floor',
'rooms',
'total_area',
'living_area',
'rooms_area',
'kitchen_area',
'number',
'price',
'base_price',
'building_id',
'mortgage_price',
'assignment',
'contractor',
'bathroom_type_id',
'balcony_type_id',
'finishing_type_id',
'view_type_id',
'entrance',
'rooms_area_separately',
'old_ID',
'published',
'meta_title',
'meta_description',
'meta_keywords',
'description',
'plan_id',
'rutube_id',
];
protected $casts = [
'is_secondary' => 'boolean',
];
protected array $allowedSorts = ['id', 'updated_at', 'published'];
protected array $allowedFilters = [
'is_secondary' => Where::class,
'building_id' => WhereIn::class,
'number' => Where::class,
'published' => Where::class,
];
public function setDescriptionAttribute($newValue): void
{
$this->attributes['description'] = $newValue ?? '';
}
// MARK: - Relations
public function building(): BelongsTo
{
return $this->belongsTo(Building::class);
}
public function options(): BelongsToMany
{
return $this->belongsToMany(FlatOption::class, FlatOptionsRelation::class, 'flat_id', 'option_id');
}
public function plan(): BelongsTo
{
return $this->belongsTo(Attachment::class, 'plan_id');
}
}