Skip to content

Tag: laravel

How to improve eloquent nested foreach performance

How can I improve the performance of a query with the following characteristics (this is a simulation to exemplify): In my real case, the foreach returns a lot of data with performance problems; The Waiting (TTFB), that is, the time the browser is waiting for the first byte of a response, takes almost 27s Ans…

Binary image from API, convert and save path

Im receiving a binary image from an API (Line API) After receiving it, I want to save the image in my public folder and save the path in my database. There were several answers on SO that I thought could work like using intervention/image but I could not manage to fix this. Ive also found a comment saying thi…

How to correctly handle laravel form?

I want to correctly handle user store form. I consider which patter will be the most correct/popular. It is repository pattern? Service pattern? Another difficulty: User form: name, email, postal code, city, street. I want to create two models in one form: User and Address. How can I solve it? I throught abou…

How to sum an associative array in laravel by there keys?

I have an array which will have an SKU number, it can be repeated so want to sum of that SKU qty at once and insert in DB table. How can i sum the same sku as index 1 and 3 have and remove the 1st index? Answer Using the solution on this Answer here is how to do it:

Search data from array of object inside foreach loop

I have 3 array. The first one is array employee, second is array dateRange(Y-m-d), and the third is array attendance The array is like this: Array Employee Array dateRange Array Attendance (both in & out) What I want to do is to get attendance data from array attendance where employee_id is the same as em…