49 lines
1018 B
PHP
49 lines
1018 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\BaseType;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Peidikeji\Keywords\Models\Keywords;
|
|
|
|
class AgriculturalBase extends Model
|
|
{
|
|
use Filterable;
|
|
|
|
protected $casts = [
|
|
'type' => BaseType::class,
|
|
];
|
|
|
|
protected $fillable = [
|
|
'type',
|
|
'name', 'person', 'address', 'address_lat', 'address_lng',
|
|
'description', 'map', 'areas', 'workforce',
|
|
'parent_id','cultivated',
|
|
];
|
|
|
|
public function scopeBase($q)
|
|
{
|
|
return $q->where('type', BaseType::Base);
|
|
}
|
|
|
|
public function scopeTown($q)
|
|
{
|
|
return $q->where('type', BaseType::Town);
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
public function crops()
|
|
{
|
|
return $this->belongsToMany(Crop::class, 'base_crops', 'base_id', 'crop_id');
|
|
}
|
|
|
|
public function yieldLogs(){
|
|
return $this->hasMany(CropYield::class, 'base_id');
|
|
}
|
|
}
|