MyHomeCollection/app/Home.php

56 lines
1.4 KiB
PHP
Raw Normal View History

2020-07-23 12:26:10 +02:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\QueryBuilder\QueryBuilder;
2020-07-23 12:26:10 +02:00
class Home extends Model
{
protected $fillable = [
'title', 'price', 'surface', 'garden_surface', 'rooms', 'energy',
'ges', 'description', 'city', 'pictures', 'map', 'url', 'pictures_downloaded',
2020-07-23 12:26:10 +02:00
];
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);
}
2020-07-24 11:06:49 +02:00
public function scopeSurfaceMax(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('surface', '<=', $price);
}
public function scopeSurfaceMin(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('surface', '>=', $price);
}
public function scopeGardenSurfaceMax(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('garden_surface', '<=', $price);
}
public function scopeGardenSurfaceMin(QueryBuilder $query, $price): QueryBuilder
{
return $query->where('garden_surface', '>=', $price);
}
2020-07-23 12:26:10 +02:00
}