2020-07-23 12:26:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-08-27 14:48:42 +02:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2020-09-04 09:44:27 +02:00
|
|
|
use Illuminate\Support\Facades\Route;
|
2020-07-23 12:26:10 +02:00
|
|
|
use Illuminate\Support\Str;
|
2020-09-04 09:44:27 +02:00
|
|
|
use Spatie\Feed\Feedable;
|
|
|
|
use Spatie\Feed\FeedItem;
|
2020-07-23 17:21:26 +02:00
|
|
|
use Spatie\QueryBuilder\QueryBuilder;
|
2020-07-23 12:26:10 +02:00
|
|
|
|
2020-09-04 09:44:27 +02:00
|
|
|
class Home extends Model implements Feedable
|
2020-07-23 12:26:10 +02:00
|
|
|
{
|
|
|
|
protected $fillable = [
|
|
|
|
'title', 'price', 'surface', 'garden_surface', 'rooms', 'energy',
|
2020-07-23 14:54:02 +02:00
|
|
|
'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);
|
|
|
|
}
|
2020-07-23 17:21:26 +02:00
|
|
|
|
|
|
|
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-08-27 14:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The "booted" method of the model.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected static function booted()
|
|
|
|
{
|
|
|
|
// Download images on creation
|
|
|
|
static::created(static function ($home) {
|
|
|
|
Artisan::call('app:downloadimage ' . $home->id);
|
|
|
|
});
|
|
|
|
}
|
2020-09-04 09:44:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function toFeedItem()
|
|
|
|
{
|
|
|
|
return FeedItem::create()
|
|
|
|
->id($this->id)
|
|
|
|
->title($this->title)
|
|
|
|
->summary($this->excerpt())
|
|
|
|
->author('Shikiryu')
|
|
|
|
->updated($this->created_at)
|
|
|
|
->link(\route('public.view', ['slug' => $this->slug]))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getFeedItems()
|
|
|
|
{
|
|
|
|
return self::where('slug', '!=', null)->limit(20)->get();
|
|
|
|
}
|
2020-07-23 12:26:10 +02:00
|
|
|
}
|