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: regenerate cache

I am using cache to store data structure from database: Cache::forever(static::DATA_STRUCTURE, json_encode($tree)); However before I generate there should cleaned old: Artisan::call('cache:clear'); But generating new cache takes some time and I want to store old cache until new will be generated.…

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
Back To Top
Search