我是 Laravel 的初学者。我的 mysql 有问题。
我有这个代码:
模型:
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');
}
}
class SelectedProductCategory extends Model
{
protected $fillable = ['product_id', 'category_id'];
protected $quarded = ['id'];
}
慕容708150