PHP code example of emrul1875 / laravel-extra-collection
1. Go to this page and download the library: Download emrul1875/laravel-extra-collection library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
emrul1875 / laravel-extra-collection example snippets
Emrul1875\LaravelExtraCollection\LaravelExtraCollectionServiceProvider::class
$collection = collect([
[
'name' => 'John' ,
'balance' => 100 ,
'image' => '/uploads/image54543534.png'
],
[
'name' => 'Jonny' ,
'balance' => 200
'image' => '/uploads/image54543534.png'
]
]);
$updatedCollection = $collection->prependValue(["balance" => "USD " , "image" : "https://dummyurl.com" ], true );
$collection = collect([
[
'name' => 'John' ,
'currency' => 'FCFA' ,
'balance' => 100 ,
],
[
'name' => 'Jonny' ,
'currency' => 'FCFA' ,
'balance' => 400
]
]);
$updatedCollection = $collection->appendValue(["balance" => " FCFA" ]);
$collection = collect([
[
'title' => 'Mr.'
'firstname' => 'John' ,
'lastname' => 'Doe'
],
[
'title' => 'Mr.'
'firstname' => 'Johny' ,
'lastname' => 'Doe'
]
]);
$updatedCollection = $collection->concatValue("fullname" , ["title" , "firstname" , "lastname" ], " " );
$collection = collect([
6 ,5 ,7 ,5 ,2 ,5 ,7 ,3 ,3
]);
$updatedCollection = $collection->at(3 )
$collection = collect([
[
'title' => 'Mr.'
'firstname' => 'John' ,
'lastname' => 'Doe'
],
[
'title' => 'Mr.'
'firstname' => 'Johny' ,
'lastname' => 'Doe'
]
]);
$updatedCollection = $collection->at(1 )
$collection = collect([
6 ,5 ,7 ,5 ,2 ,5 ,7 ,3 ,3
]);
$updatedCollection = $collection->find(function ($item) {
return $item > 5 ;
});
$collection = collect([
[
'title' => 'Mr.'
'firstname' => 'John' ,
'lastname' => 'Doe' ,
'age' => 20
],
[
'title' => 'Mr.'
'firstname' => 'Johny' ,
'lastname' => 'Doe' ,
'age' => 25
]
]);
$updatedCollection = $collection->find(function ($item) {
return $item->age > 15 ;
})
$collection = collect([
6 ,5 ,7 ,5 ,2 ,5 ,7 ,3 ,3
]);
$updatedCollection = $collection->findIndex(function ($item) {
return $item > 5 ;
});
$collection = collect([
[
'title' => 'Mr.'
'firstname' => 'John' ,
'lastname' => 'Doe' ,
'age' => 20
],
[
'title' => 'Mr.'
'firstname' => 'Johny' ,
'lastname' => 'Doe' ,
'age' => 25
]
]);
$updatedCollection = $collection->findIndex(function ($item) {
return $item->age > 20 ;
})