再会。 laravel 中使用 with() 函数时是否可以使用别名?举个例子:
$posts = Post::where(/*condition*/)->with('user as friend')->get();
简短的回答是否定的,但您可以定义与要使用的别名的关系并立即加载它。
class Post extends Model
public function user(){
return $this->belongsTo(User::class);
}
public function friend(){
return $this->user()
}
}
$posts = Post::where(/*condition*/)->with('friend')->get();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)