小编ral*_*alu的帖子

Laravel Eloquent:如何仅从连接表中获取某些列

我在Eloquent中有2个连接表,即主题和用户.

主题模型:

public function user() {
  return $this->belongs_to('User');
}
Run Code Online (Sandbox Code Playgroud)

用户模型:

public function themes() {
  return $this->has_many('Theme');
}
Run Code Online (Sandbox Code Playgroud)

我的Eloquent api电话如下:

return Response::eloquent(Theme::with('user')->get());
Run Code Online (Sandbox Code Playgroud)

它返回主题中的所有列(没关系),以及来自用户的所有列(不是很好).我只需要用户模型中的"用户名"列,如何限制查询?

php laravel eloquent

95
推荐指数
10
解决办法
18万
查看次数

标签 统计

eloquent ×1

laravel ×1

php ×1