mercredi 6 septembre 2017

Implement select function in Eloquent with

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire