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

why can't orderby desc and asc work? in laravel

example image data : when the js responds, the data has already been ordered by example image response js : example controller and query : $query = Verifikasi_tte::join('surat_ttes', 'surat_ttes.id', '=', 'verifikasi_ttes.surat_tte_id') ->join('users', 'users.id', '=', 'surat_ttes.user_id') ->join('jenis_surat_ttes', 'jenis_surat_ttes.id', '=', 'surat_ttes.jenis_surat_tte_id') ->select('surat_ttes.id','surat_ttes.klasifikasi','surat_ttes.no_surat','surat_ttes.tgl_surat','surat_ttes.created_at',…

VIEW QUESTION
Back To Top
Search