skip to Main Content

How to use multiple subqueries in Laravel's Eloquent?

I have a SQL query like this: SELECT year FROM ( SELECT my_custom_function_for_get_year(week_start::date) AS year FROM ( SELECT date_trunc('week', week_start) AS week_start FROM generate_series('2023-01-01'::date, '2023-12-31'::date, interval '1 week') gs(week_start) ) as select1, (SELECT id FROM mytable) as select2 ) as…

VIEW QUESTION

Override last() method in laravel

I have one to many relations In my User Model public function user_balances(){ return $this->hasMany(UserBalances::class); } In my User Balances Model public function user(){ return $this->belongsTo(UserBalances::class); } So every time I want to retrieve the last record of user balance,…

VIEW QUESTION

Laravel DB::transaction()

I have some code and tried it in two ways. It's not working as expected and is not rolling back data Error produce example is in git : https://github.com/Namvarii/laravel-db-transaction-error DB::beginTransaction(); try { $order = Order::create([ // data ]); $order->notes()->create([ //…

VIEW QUESTION

Laravel many to many whereDoesntHave

I have this code here simplified. Post::whereDoesntHave('tags', function($query){ $query->whereIn(tags.id, $tagIds); }) Lets say that tagIds = [1,2,3] My goal is to retrieve only Posts that do not contain all of those tags. ex. if post has tags 1,2,3 , then…

VIEW QUESTION
Back To Top
Search