Category : collections

I am workign with a Laravel collection and given this code: use IlluminateSupportCollection; $input = [‘1234′, 42, ’12Beers’]; $result = new Collection($input)->each(static function($item) { return (int) $item;} )->toArray(); I’d expect the result to look like: [ 0 => 1234 1 => 42 2 => 12 ] but I’m getting: [ 0 => "1234" 1 => ..

Read more

I’m having trouble put values into collection laravel I’ve read this with the same problem but didnt worked on me reference This is my collection IlluminateSupportCollection {#1348 #items: array:9 [ 0 => {#1350 +"id": 532 +"id_user": "BR001" +"name": "Jack" +"department": "HR +"City": "London" +"updated_at": "2021-04-08 15:37:32" } 1 => {#1351 +"id": 522 +"id_user": "BR002" +"name": ..

Read more

Am I able to unset whole collection element inside transform? $jsonArrLive->transform(function ($i,$k) { $test = $i[0]->some ?? null; if(!$test) { return null; } } Now i get [‘arr1=>..’,null] and I want to remove this null inside transform to get just [‘arr1=>..’] as result I added: $jsonArrLive = $jsonArrLive->filter(function ($value, $key) { return $value != null; ..

Read more

I have two tables as below pscustom_catalog_product_entity pscustom_catalog_product_entity_media I have created collection for table pscustom_catalog_product_entity using resource model and block. Now I can access this table data using collection. app/code/MyModule/Productsinfo/Model/Product.php <?php namespace MyModuleProductsinfoModel; use MagentoFrameworkModelAbstractModel; use MyModuleProductsinfoModelResourceModelProduct as ResourceModel; class Product extends AbstractModel { protected function _construct() { $this->_init(ResourceModel::class); } } app/code/MyModule/Productsinfo/Model/ResourceModel/Product.php <?php namespace MyModuleProductsinfoModelResourceModel; ..

Read more

When I’m using map() in DB query. I’m getting this result { "success": true, "message": "Purchase Order Generated", "data": [ { "po_date": "2015-05-24 00:00:00", "items": { "item_name": "Tata Steel", "specifications": "steels", "unit": "ton", "quantity": "100", "price": "1200", "amount": "120000" } }, { "po_date": "2015-05-24 00:00:00", "items": { "item_name": "Tata Steel 2", "specifications": "steels 1", "unit": ..

Read more

I’m using external API for my website. When user select city and town, API returns neighborhoods. But the problem is, if there is only one neighborhood array contains name and neighborhood id. But if there is more than one, it contains multiple array for each neighborhood. Single example ; array( ‘Code’ => 123, ‘NeighborhoodName’ => ..

Read more