0, 'thumb' => '', 'description' => '', 'adv_img' => '', 'adv_url' => '', ]; /** * 不可填充字段. * * @var array */ protected $guarded = ['']; //protected $fillable = ['']; /** * @param $parent_id * @param $pageSize * @return mixed */ public static function getCategorys($parentId) { return self::uniacid() ->where('parent_id', $parentId) ->orderBy('display_order', 'desc'); } public static function checkCategory($ids=[]){ if (!$ids) return false; if(!$category_data = self::uniacid()->whereIn('id',$ids)->orderBy('level','ASC')->get()) return false; $parent_id = 0; $category_data->each(function ($v) use (&$parent_id){ if ($v->level != 1 && $v->parent_id != $parent_id){ return false; } $parent_id =$v->id; }); return true; } /** * @param $parentId * @param $set * @return mixed */ public static function getChildrenCategorys($parentId, $set = []) { $model = self::uniacid(); if ($set['cat_level'] == 3) { $model->with(['hasManyChildren'=>function($qurey){ return $qurey->where('enabled', 1) ->orderBy('display_order', 'desc'); }]); } $model->where('parent_id', $parentId); $model->where('enabled', 1); $model->orderBy('display_order', 'desc'); $model->orderBy('id', 'asc'); return $model; } /** * @return mixed */ public static function getRecommentCategoryList() { $model = self::uniacid(); return $model; } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function hasManyChildren() { return $this->hasMany(self::class, "parent_id"); } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function goodsCategories() { return $this->hasMany('app\common\models\GoodsCategory', 'category_id', 'id'); } public function scopePluginId($query) { return $query->where('plugin_id', 0); } }