mardi 1 mars 2016

Nested eager loading in where clause in Laravel

I want to know is there anyway to write query like this in Laravel using Eloquent. I mean can i do eager loading in where clause. I am stuck here from last day and i really want to do like this. So suggestions needed.

        $notifications = Notification::where('user_id',Auth::user()->id)
            ->where('is_try', '!=', Config::get('constants.NOTIFICATION_AGAINST_JOB_TURN_DOWN'))
            ->where('is_try', '!=', Config::get('constants.NOTIFICATION_AGAINST_JOB_EXPIRED'))
            ->where(function($query) {
                $query->where(function($query) {
                    $query->where('message', '!=', 'job_post')
                        ->with(['suggestion' => function ($query) {
                            $query->with(['job' => function ($query) {
                                $query->with('company');
                            }]);
                        }]);
                    })
                    ->orWhere(function($query){
                        $query->where('message','job_post')
                        ->with(['job' => function ($query) {
                            $query->with('company');
                        }]);
                });
            })
            ->orderBy('notifications.created_at','desc')
            ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire