美好的一天。 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();
关于php - Laravel Eloquent 在 with() 函数中使用别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49018265/