skip to Main Content

Laravel When Condition on a column

I have a ModelA with columns: name, last_name, email I want ModelA with the name Test to add an extra where on email what I tried is the following $model_a_res = A::when( function($query){ return $query->where('name','Test'); }, function ($query) { $query->where('email',…

VIEW QUESTION

Laravel OrWhereNull giving wrong results

I have this long query builder where I am basically searching a table and then filter the results based on the passed query strings: $projects = Listing::query() ->when(request('q'), function($builder) { $builder->searchQuery(request('q')); }) ->when(request('tags'), function($builder) { $tags = request('tags'); $builder->whereHas('tags', function($builder)…

VIEW QUESTION

Laravel – ID getting lost during delayed job

I'm dispatching a delayed job that should created some entries in the database: `$userId = Auth::user() ? Auth::user()->getAuthIdentifier() : null; $job = new DelayedAddPeopleJob($event, $userId); dispatch($job)->delay(DelayedAddPeopleJob::DELAY);` After 15 minutes DelayedAddPeopleJob is executed and in there im creating entries in the…

VIEW QUESTION

Laravel Model attribute

I am using a third party table which very annoyingly has name and surname fields. The first name goes into name and of course the surname goes into surname. I want to concat these together in the model as I…

VIEW QUESTION

Laravel eloquent GROUP BY

I have four tables: supplies, stocks, stock_ins, and stock_outs. In the Stock controller, I want to sum the total stock_out for each supply . For this, I have used the following query: $supplies = Stock::select( 'supplies.name', 'stocks.supply_id', 'stocks.id', 'stocks.stock', 'stock_ins.quantity…

VIEW QUESTION
Back To Top
Search