skip to Main Content

Search Query by Child field Eloquent relation – Laravel

My Product Model is public function IncomeRepo(){ return $this->hasMany(Income::class,'Product'); } My Income Report Model Is public function ProductData(){ return $this->belongsTo(Product::class,'Product','id'); } My Query is public function SearchIncomeData(Request $request){ $GetFromDate = $request->FromDate; $GetToDate = $request->ToDate; $ProductData = Product::with('IncomeRepo')->whereBetween('created_at', [$GetFromDate, $GetToDate])->get(); return…

VIEW QUESTION

Why the count alias column is not returned as part of ActiveRecord_Relation? – Postgresql

I have two tables. StudentGroup and StudentGroupsMembers. StudentGroup.id = StudentGroupMembers.group_id is the foreign key relation. sg = StudentGroup.joins(:student_group_members).select(" student_groups.id, student_groups.name, count(student_group_members.id) as cnt ").group('student_group_members.group_id, student_groups.name, student_groups.id').where(id: [3,4,5,6,6,7,7,8,8]).where("student_group_members.member_type='ra'") This return ActiveRecord_Relation [#<StudentGroup:0x00007fc11253d088 id: 3, name: "Blah">, #<StudentGroup:0x00007fc11253cc78 id: 4, name: "Foo">,…

VIEW QUESTION
Back To Top
Search