Category : laravel-collection

I have the following piece of code : $callReport = array(); $callResult->each(function ($item) use (&$callReport) { $callCenterReport[$item->date][$item->callStatus] = $item->count; }); The $callReport result is : { "2020-11-25": { "x": 74, "y": 172, }, "2020-11-26": { "x": 10, "y": 49, } } But when i try with the collect methods : $callReport = collect(); $callResult->each(function ($item) ..

Read more

I have this result returned by Eloquent. Already sorted effective_at Ascending [ { "id": 2200155, "price": "0.07980", "effective_at": "2020-10-01" }, { "id": 2218010, "price": "0.07870", "effective_at": "2020-10-06" }, { "id": 2256374, "price": "0.07960", "effective_at": "2020-10-15" }, { "id": 2273713, "price": "0.08460", "effective_at": "2020-10-19" }, { "id": 2300540, "price": "0.08460", "effective_at": "2020-10-26" } ] I want ..

Read more

I have a Laravel collection of Carbon dates: $dates = collect([ Carbon::parse(‘2020-09-18’), Carbon::parse(‘2020-09-21’), Carbon::parse(‘2020-09-22’), Carbon::parse(‘2020-10-13’), Carbon::parse(‘2020-10-14’), Carbon::parse(‘2020-10-15’), Carbon::parse(‘2020-11-02’), Carbon::parse(‘2020-11-03’), Carbon::parse(‘2020-11-04’), Carbon::parse(‘2020-11-05′) ]); I want to split these into chunks where the dates are consecutive weekdays. I’ve managed to use chunkWhile to split the collection where the dates are either before or after: $chunks = $dates->chunkWhile(function ..

Read more

I wanna test my livewire store functionality. public function store() { $validated = $this->validate( [ ‘service_id’ => ‘required’, ‘price’ => ‘required|regex:/^[0-9]{1,5}([,.][0-9]{1,2})?$/’, ‘option_available.*’ => ‘boolean’, ‘option_price.*’ => ‘regex:/^[0-9]{1,5}([,.][0-9]{1,2})?$/’ ] ); // formatting price $validated[‘price’] = (float) str_replace(‘,’ , ‘.’, $validated[‘price’]); $service = $this->services->find($validated[‘service_id’]); $options = collect([]); if ( $this->serviceOptions ) { foreach ($this->serviceOptions as $key => ..

Read more

I have below array: $arr[123][‘price’] = 100; $arr[456][‘price’] = 500; $arr[100][‘price’] = 1000; $arr[511][‘price’] = 200; Now I want to sort it by price, so I did below operation: $arr = collect($arr); $sorted = $arr->sortBy(‘price’); Array gets sorted & dd($sorted) gives me below result: Collection {#957 ▼ #items: array:4 [▼ 123 => array:1 [▼ “price” ..

Read more

I need to display a list of category label from a filtered collection seperated by comma in blade views. The code looks like this {{$data->categories->filter(function ($value) {return $value->type_id == 1;})->pluck([‘label’])->toArray()}}; This error is when I use toArray() htmlspecialchars() expects parameter 1 to be string, array given I need the result in array to use it ..

Read more