我有一个属于User的Notifications模型。我希望在选择通知集合时加载用户,并且只使用names和emails加载模型。但是,当使用select方法时,查询返回null。
$notifications->load(['user' => function($query){
    $query->select(["name","email"]);
}]);如果select()方法的参数如下,则会给出所有字段:
$notifications->load(['user' => function($query){
    $query->select(["*"]    
}]);发布于 2020-10-11 17:40:51
如果使用select处理数据,则必须传递foreign_key。看一看
public function index()
{ 
    $employee = Employee::with(['pay_salary' => function($query){
       $query->select(['employee_id','salary_amount'])
             ->whereMonth('paying_date',\Carbon\Carbon::now()->month);
    },'getSalary:id,employeeID,salary'])->get();
    
    return View::make('admin.salary.index',['data' => $employee]);
}https://stackoverflow.com/questions/50623064
复制相似问题