#### Category : collections

This is an example that I have a problem with. 0 => array:3 [ "ID" => 1 "limitStock" => "123" "reduce" => "400.00" ] 1 => array:3 [ "ID" => 1 "limitStock" => "223" "reduce" => "0.00" ] 2 => array:3 [ "ID" => 1 "limitStock" => "232" "reduce" => "0.00" ] 3 => array:3 ..

Read more

Laravel I have a problem finding a data inside a collection which is filled with objects. My collection is look like this: return collect([ new Aligator(‘1’, ‘name1’), new Aligator(‘2’, ‘name2’), new Aligator(‘3’, ‘name3’)]; The data which I want to search is the name, given through url with contoller. Route::get(‘/aligator/{name}’, [AligatorController::class, ‘getAligator’]; After clicking the link ..

Read more

I have this in my collection [ "pending" => array:2 [ "count" => 2 "amount" => 200 ] "ongoing" => array:2 [ "count" => 3 "amount" => 3000 ] "price_total" => 7000 ] what i want to achieve is like to seperate the count and amount [ "pending" => array:1 [ "amount" => 200 ] ..

Read more

I have a method in my controller public function studentDirectory(Request $request, Student$student) { if($request->switch == ‘personal’) { return new StudentResource($student); } } Resource Controller: public function toArray($request) { return [ ‘id’ =>$this->id, ‘name’ => $this->name, ‘address’ =>$this->address, ‘phone’ => $this->phone, ‘tags’ => TagsResource::collection($this->tags)), ]; } Now this works fine and I get ..

Read more

Hello dear Stack overflowers, I’m trying to compare one collection with the name ‘text1’, with another collection ‘text2’. I would like to achieve that it puts all values, that ‘text1’ and ‘text2’ both have, into another collection. I already tried using Diff and DiffKeys (see compare two collection arrays in laravel ). But I was ..

Read more

I want to sort two laravel collection after merging them in alphabetical order, I’ve used the following code: $result =$commonTitles->merge($newTitles)->sort(); And the result is sorted A to Z and then a to z. ["Ask","Black","Unit","ab","live","test"] The result that I expect is sorting as A a to z Z. How can I change the result? Source: .. Read more I’m working on a php project and need to use the Collection namespace from Illuminate. I have Laravel installed on my computer. However, when I try and create a new collection with: use IlluminateSupportCollection; …$collection = new Collection(); It gives me the error that it cannot find the class "IlluminateSupportCollection." I tried moving my ..

Read more

I need to add pagination, but it seems complicated in my case, because I get data from database with paginate, but then I modify this data and when I call links() method on the blade, I get the following exception Method IlluminateSupportCollection::links does not exist. My code in the Controller method: $transactionsByLastMonth = Transaction::where(‘created_at’, ‘>=’, .. Read more I try to paginate a sorted collection in Laravel 8, maybee any one have an idea? That’s my code:$where = Business::where(‘name’, ‘LIKE’, ‘%’ . $what . ‘%’);$businesses = $where->get()->sortByDesc(function($business) { return $business->totalReviews; })->paginate(10); // <— not working.. Collection::paginate not exists Sourc.. Read more I’ve been trying to get the difference between two collections: 1st: { "name": "Test A", "scores": [ { "name": "Values", "points": 9 }, { "name": "Algebra", "points": 6 }, { "name": "Science", "points": 5 }, { "name": "Total", "points": 20 } ] } 2nd: { "name": "Test A", "scores": [ { "name": "Values", "points": 5 .. Read more What is difference between items of collection & attributes of collection ? How should we change this in each other ? Sourc.. Read more I have a resource in this resource I have collection , now I want to show that collection pagination links how can I do it? This is my resource public function toArray($request) { return [ "name" => $this->name , "slug" =>$this->slug , "bg_image" => imageGenerate("sections" , $this->bg_image) , "bg_color" =>$this->bg_color , "items" => ..

Read more

I have an issue with a form data. I have many files in an array but when I have to get them in my controller I use file() but it doesn’t returns a collection of uploaded files, so I’m looking for a solution to make it possible. My client is Anguler and my API is ..

Read more

I have an issue with a form data. I have many files in an array but when I have to get them in my controller I use file() but it doesn’t returns a collection of uploaded files, so I’m looking for a solution to make it possible. My client is Anguler and my API is ..

Read more

I’m trying to figure out the best way to sort by multiple values and multiple keys at once. I have the following "sort sequence"; sort by "finished or not" sort by "out of time or not" sort by "points in total" sort by "points for your time" sort by "points for each ‘secret time control’, ..

Read more

Hello guys! I got a task and i need your help. Firstly i would like to show you my AppRepositoriesxyz.php App/repositories/xyz.php public function getcars(): Collection { return collect([ new Car(…) )]; There is a lot of data in it. And my task is that i have to use a Http Get Api endpoint to show ..

Read more

Hello guys! I have a a little problem with collections. I have never worked with these. I would like to display a collection at my welcome blade but there is a problem. My collection is not in the contrroller, the collection’s place is in the App/Repositories/xyz.php and in a function. How can i pass this ..

Read more

Given the following collection: $client = Client::all(); //all: [ // AppModelsClient { // #id: 1, // name: "Roark", // }, // AppModelsClient { // #id: 2, // name: "Tanika", // }, // AppModelsClient { // #id: 3, // name: "Max", // }, // AppModelsClient { // #id: 4, // name: "Sloane", // }, //], and .. Read more I have a laravel collection below from:$unitinventory = DB::select(‘call wh_inventory_list(?)’, array(‘Units’)); [ { "unit_id":"UCL2100001", "rr_id":"RR2100001", "make":"FAW", "chassis_no":"LFWSRXRJ9M1E00004", "engine_no":"CA6DM2-42E5153558354", "body_type":"TRACTOR HEAD", "horse_power":"420HP", "cabin_type":"J6P E5", "numwheels":"6W", "unit_status":"Available", "unit_location":null }, { "unit_id":"UCL2100002", "rr_id":"RR2100002", "make":"FAW", "chassis_no":"LFWSRXRJ4M1E00007", "engine_no":"CA6DM2-42E5153563283", "body_type":"TRACTOR HEAD", "horse_power":"420HP", "cabin_type":"J6P E5", "numwheels":"6W", "unit_status":"Available", "unit_location":null } ] And another collection: $modifification = collect(DB::table(‘pd_jo_bodymodification’)->get()); [ { "row_id":2, "jo_id":"JO2100003", "jo_chassisno":"LFWSRXRJ4M1E00007", .. Read more I have two collections. First Collection is all descendants (not children) from root item, flat structure, in other words, ALL items in my DB in flat organization:$descendants = $root->getDescendants(); I go through this collection using foreach: foreach ($descendants as $key => &$item) {} For each item, I do some magic, but then, I need ..

Read more

I have an $attendace variable contains a collection from a Laravel query builder:$attendace = [ { "row_id":65, "emp_number":"IPPH0004", "time_stamp":"01:00:00", "attendance_status":"Punch In", "date_created":"2021-10-02" }, { "row_id":68, "emp_number":"IPPH0004", "time_stamp":"07:30:00", "attendance_status":"Start Break", "date_created":"2021-10-02" }, { "row_id":69, "emp_number":"IPPH0004", "time_stamp":"08:00:00", "attendance_status":"End Break", "date_created":"2021-10-02" }, { "row_id":70, "emp_number":"IPPH0004", "time_stamp":"08:30:00", "attendance_status":"Start Break", "date_created":"2021-10-02" }, { "row_id":71, "emp_number":"IPPH0004", "time_stamp":"09:00:00", "attendance_status":"End Break", "date_created":"2021-10-02" ..

Read more

I am trying to get the value from a collection in PHP. $todaylog variable contains a collection from a laravel query builder:$todaylog = [ { "row_id":55, "emp_number":"IPPH0004", "timestamp":"03:30:23", "attendance_status":"Punch In", "date_created":"2021-10-01" }, { "row_id":56, "emp_number":"IPPH0004", "timestamp":"11:32:50", "attendance_status":"Start Break", "date_created":"2021-10-01" }, { "row_id":57, "emp_number":"IPPH0004", "timestamp":"11:33:09", "attendance_status":"End Break", "date_created":"2021-10-01" } ] What I have done so ..

Read more

i have a ressource collection : class OverviewResource extends JsonResource { public function toArray($request): array { return [ ‘first_name’ =>$this->first_name, ‘last_name’ => $this->last_name, ’email’ =>$this->email, ‘phone’ => $this->phone, ‘friends’ => OverviewResource::collection(User::getFriends()), ]; } } i have an error in this line ‘friends’ => OverviewResource::collection(User::getFriends()), when calling this function from User model public static .. Read more In the following code, the "liked_by_me" column remains unchanged but the "newAttr" column is added.$commentList->transform(function($item,$key) { $item->liked_by_me == null ?$item->liked_by_me = false : $item->liked_by_me = true;$item->liked_by_me == null ? $item->newAttr = false :$item->newAttr = true; return $item; }); The$commentList collection is the result of a read from the DB ..

Read more

I have the following tables: users id name cattle_types id user_id name properties id user_id name properties_cattle_types id cattle_type_id property_id quantity I get all cattle types related to user through hasMany relation defined in user model: Auth::user()->cattleTypes But I need also take SUM of ‘quantity’ all notes that defined in pivot table properties_cattle_types. I don’t ..

Read more