I'm trying to implement a simple select method into a eloquent with. So, I have this code that works correctly.
$usersInfo = User::with(['product' => function($query) use($request) {
$query->whereBetween('date', [$request->get('datefrom'), $request->get('dateto')]);
}])->get();
But if I put a select into the query function, the query stop working and return an empty value into the product array.
$usersInfo = User::with(['product' => function($query) use($request) {
$query->select(['date', 'name'])
->whereBetween('date', [$request->get('datefrom'), $request->get('dateto')]);
}])->get();
I know that if use DB::table()
is possible to do this stuff.
So, my question is. If there any possibility to put this select into the with, in Eloquent?
Thanks