桌子:
Schema::create('shippings', function (Blueprint $table) {
$table->id();
$table->string('name',64);
$table->integer('price');
$table->enum('active', ['yes','no'])->default('yes');
$table->timestamps();
});
}
模型:
class Shipping extends Model
{
const YES = 'yes';
const NO = 'no';
public function isActive()
{
return $this->active == self::YES;
}
}
我想通过使用这样的模型功能只显示活跃的
$shipping = Shipping::with('isActive')->get();
但后来我得到
错误 调用 bool 上的成员函数 addEagerConstraints()
我做错了什么还是不可能以这种方式做到这一点?