skip to Main Content

Laravel 10 relation dynamic variable in subquery

How can I call a dynamic variable in a subquery? I have some relations and call them like: $locations = Location::query() ->with('brands', function ($query) { $query->with('employees')->where('location_id', {dynamic ID of brand location}); }) ->get(); The relation in the Location.php Class: public…

VIEW QUESTION

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

Postgresql – SQL: Select distinct items where condition is met

I have a relation in a database as follows: constituents Symbol [{"weight":0.5, "ticker":"WPM"},{"weight":0.5, "ticker":"AEM"}] GLD [{"weight":0.5, "ticker":"XYZ"},{"weight":0.5, "ticker":"ABC"}] KLE [{"weight":1.0, "ticker":"TSLA"}] TSLA [{"weight":1.0, "ticker":"MSFT"}] MSFT [{"weight":0.4, "ticker":"XYZ"},{"weight":0.6, "ticker":"ABC"}] KLE [{"weight":0.3, "ticker":"BBBY"},{"weight":0.7, "ticker":"GME"}] MEME I want to get the distinct symbols…

VIEW QUESTION

Laravel MongoDB 1:n relations

What is the correct way of defining 1:n relations in Laravel using MongoDB between two models Author and Book where one author can have several books while one book has exactly one authors? Author.php class Author extends Model { public…

VIEW QUESTION
Back To Top
Search