48 lines
956 B
PHP
48 lines
956 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Dcat\Admin\Traits\ModelTree;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Peidikeji\Keywords\Models\Keywords;
|
|
|
|
class Crop extends Model
|
|
{
|
|
use ModelTree,Filterable,HasDateTimeFormatter;
|
|
|
|
protected $titleColumn = 'name';
|
|
|
|
protected $orderColumn = 'sort';
|
|
|
|
protected $casts = [
|
|
'extends' => 'array',
|
|
];
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('sort', 'desc')->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
protected $fillable = [
|
|
'category_id',
|
|
'name', 'parent_id',
|
|
'unit',
|
|
'path', 'is_end',
|
|
'sort',
|
|
'extends',
|
|
'crop_type',
|
|
];
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(Keywords::class, 'category_id');
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_id');
|
|
}
|
|
}
|