with(['Category','Shop']) ->when($keywords != '', function ($query) use ($keywords){ $query->where('appointment_name', 'like', '%' . $keywords . '%'); }) ->where('appointment_del',0) ->orderBy('appointment_create_time','DESC') ->forPage($page, $limit) ->get(); $count = static::when($keywords != '', function ($query) use ($keywords){ $query->where('appointment_name', 'like', '%' . $keywords . '%'); }) ->where('appointment_del',0)->count(); return [$list, $count]; } public function getAppointmentCreateTimeAttribute($value) { return date('Y-m-d H:i:s', $value); } public function Category(){ return $this->belongsTo(Category::class,'appointment_category_id','category_id'); } //关联店铺 public function Shop(){ return $this->belongsTo(MerchantShop::class,'appointment_shop_id','shop_id'); } }