skip to Main Content

Combing multiple orWhere() in Laravel 9 Eloquent

Is it possible to combine multiple orWhere() inside one where()? E.g. The following: $query->where(function($query){ $query->where('text1', '=', $_GET['lorem']) ->orWhere('text2', '=', $_GET['lorem']) ->orWhere('text3', '=', $_GET['lorem']) ->orWhere('text4', '=', $_GET['lorem']); }); Would look something like this: $query->where(function($query){ $query->where(['text1' || 'text2' || 'text3' || 'text4'],…

VIEW QUESTION

withSum in deep nested relationship in laravel eloquent

I could not find this in the laravel docs on aggregate relationships I was able to do something like this private function refreshUsers() { $this->users = User::withSum(['taskTimeSessions'=> function ($query) { $query->whereMonth('created_at',$this->month) ->where('is_reconciled',1); }],'session_duration_in_seconds') ->get(); } But now I am trying…

VIEW QUESTION

Route model binding select specific columns with relation – Laravel

Route: Route::get('/posts/{post}', [PostController::class, 'show']); Controller: public function show(Post $post){ $postData = $post->load(['author' => function($query){ $query->select('post_id', 'name'); }]) ->get(['title', 'desc', 'created_date']) ->toArray(); } This returns all the posts in the database, While I only want to get the selected post passed…

VIEW QUESTION
Back To Top
Search