【发布时间】:2018-09-11 10:37:54
【问题描述】:
我只想获取 wef 等于当前表 wef 的类型。如何实现这一点我无法使用 $this->attributes['wef'] 获取 wef 属性。提前致谢。
class Gst extends Model
{
//
use Traits\UserAutoUpdate;
protected $connection = 'mysql';
protected $table = "gst";
protected $fillable = ['name','wef'];
public function types(){
return $this->hasMany(GstType::class,'gst_id','id')->where('wef', $this->attributes['wef']);
}
}
错误: "未定义索引:wef"
【问题讨论】:
-
我认为
$this->attributes['wef']不会起作用。您需要在types()函数的参数中传递值。 -
如果您正在使用急切加载.. 获取属性只是
$this->wef -
@Neha 工作正常吗?
-
作为@DigitalDrifter 的回答.. 最好按照建议去做。