我试着像页面上显示所有位置:如何在Laravel中创建关系?
{{$item->country()->first()->name}}, {{$item->city()->first()->name}}, {{$item->location()->first()->name}}
你可以从关系country
,city
,location
看到这些值。
如何在这种情况下创建存取器?在哪个模型中写入访问器?
我尝试这样做:
public function setTeacherNameAttribute()
{
$this->attributes['teacher_name'] = $this->country->name;
}
我不明白你要做什么。 “在这种情况下如何创建存取器?在哪个模型中写入存取器?”这个访问器会做什么? – devk