MyHomeCollection/app/Home.php

36 lines
825 B
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\QueryBuilder\QueryBuilder;
class Home extends Model
{
protected $fillable = [
'title', 'price', 'surface', 'garden_surface', 'rooms', 'energy',
'ges', 'description', 'city', 'pictures', 'map', 'url', 'pictures_downloaded',
];
protected $casts = [
'map' => 'array',
'pictures' => 'array',
];
public function excerpt()
{
return Str::words($this->description, 10);
}
public function scopePriceMax(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('price', '<=', $price);
}
public function scopePriceMin(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('price', '>=', $price);
}
}