我是 Laravel 的初学者。我做了一个功能来显示带有过滤器的产品列表。
我的代码有一个小问题
我有这个代码:
class Product extends Model
{
use ScopeActiveTrait;
use Slugable;
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
$this->attributes['slug'] = $this->makeSlug($value);
}
protected $fillable = ['delivery_time', 'product_type', 'name', 'title', 'description', 'keywords', 'content', 'vat_id', 'main_category_id', 'enable', 'slug', 'small_description'];
protected $quarded = ['id'];
public $timestamps = false;
public function vat()
{
return $this->belongsTo('App\Models\VAT', 'vat_id');
}
public function category()
{
return $this->belongsTo('App\Models\Category', 'main_category_id');
}
public function selectedCategory()
{
return $this->hasMany('App\Models\SelectedProductCategory', 'product_id', 'id');
}
public function related()
{
return $this->belongsTo('App\Models\RelatedProduct');
}
public function features()
{
return $this->hasMany('App\Models\SelectedProductFeature');
}
public function frontImage()
{
return $this->hasMany('App\Models\UploadImage', 'file_id', 'id')->orderBy('order', 'ASC')->where('file_type', 'products');
}
}
慕森王