1 回答

TA貢獻1876條經驗 獲得超7個贊
首先,您似乎正在使用該庫: https:?//github.com/Kyslik/column-sortable
$sortable
您中的屬性與數組AddonCategory
元素和表的列名相匹配。因此,您收到錯誤:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'addons_count' in 'order clause'
addons_count
鑒于MySQL 表中不存在該列addon_category
,并且由 laravel 作為屬性添加,您需要實現Aliasing
,這是在庫的文檔中指定的
您的最終模型將如下:
class AddonCategory extends Model
{
? ? use Sortable;
? ? protected $casts = ['addons_count' => 'integer'];
? ? public $sortable = ['name', 'type', 'created_at'];
? ? public $sortableAs = ['addons_count'];
? ? public function items()
? ? {
? ? ? ? return $this->belongsToMany(Item::class);
? ? }
? ? public function addons()
? ? {
? ? ? ? return $this->hasMany('App\Addon');
? ? }
}
其余的實施都很好。
- 1 回答
- 0 關注
- 90 瀏覽
添加回答
舉報