我想查询使用与访问者与 getNameAttribute的关系,这是我的代码Laravel getRelations()返回空白
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Conference extends Model{
public function getNameAttribute() {
return $this->getRelation('event')->name;
}
public function event() {
return $this->belongsTo('App\Event');
}
public function speakers() {
return $this->hasMany('App\Speaker');
}
}
但它returnin什么..我是不是错误? 谢谢!
哦,哇,这很容易,它如何获得该事件?通过雄辩的ORM? – Notflip
@Notflip是的,它触发了雄辩的魔法'__get'方法。你可以查看[文档](http://laravel.com/docs/5.0/eloquent)它有很多很酷的技巧和提示。 – shaddy
这更容易,然后我无法想象!谢谢 – Notflip