首页 > 解决方案 > 如何使用父 $table 属性从父类的子类运行 Eloquent create()?

问题描述

我有以下课程

class Business extends Eloquent {
     protected $table = 'business';
     protected $fillable = [{stuff}];
}

class Employee extends Business {
     protected $table = 'employee';
     protected $fillable = [{stuff}];

     public function business_create(array $attributes = []) {
        parent::create($attributes);
     }
}

当我尝试运行 business_create() 时,Eloquent 尝试在“员工”表上创建一条记录。如何在父类上从子类运行创建使用父属性?

标签: phpoopinheritanceeloquentattributes

解决方案


推荐阅读