mercredi 26 septembre 2018

Call to a member function getQuery() on null Laravel Eloquent

I have worked a lot with Laravel and never got the following error:

Call to a member function getQuery() on null at /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php line 558.

I'm trying to get a record with all the relationships specified. The code that is causing that error is the following:

        $id = 7;
        $compra = Compra::where('id', $id)
                            ->with(['certificado',
                                    'certificado.duracionServicios', 
                                    'certificado.duracionServicios.servicio', 
                                    'certificado.duracionServicios.servicio.traducciones' => function($query){
                                         $query->whereHas('idiomas', function($q){
                                             $q->where('codigo_region', 'es_MX');
                                         });
                                     },
                                    'user'])
                                    ->first();

If I take out the first() method, I can print the object instance of Builder, but when I try to use it or even use get(), that exception is thrown. Laravel version I'm using is 5.5



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire