PHP code example of liyuze / laravel-method-chaining-macros

1. Go to this page and download the library: Download liyuze/laravel-method-chaining-macros 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');

/* Start to develop here. Best regards https://php-download.com/ */

    

liyuze / laravel-method-chaining-macros example snippets


collect([1,2,3])->chaining()->map(fn ($v) => $v * 2)->sum()->popValue();    //12
collect([1,2,3])->pipeChaining()->map(fn ($v) => $v * 2)->sum()->popValue();    //Collection([2,4,6])

$list = collect([1,2,3]);
$list->ifChaining(true)->map(fn ($v) => $v * 2)->sum()
    ->elseChaining()->map(fn ($v) => $v * 3)->avg()
    ->endIfChaining();    //12
    
$list->ifChaining(false)->map(fn ($v) => $v * 2)->sum()
    ->elseChaining()->map(fn ($v) => $v * 3)->avg()
    ->endIfChaining();    //6

$list = collect([1,2,3]);
$list->unlessChaining(true)->map(fn ($v) => $v * 2)->sum()
    ->elseChaining()->map(fn ($v) => $v * 3)->avg()
    ->endUnlessChaining();    //6
bash
php artisan vendor:publish --provider="Liyuze\MethodChainingMacros\MethodChainingMacrosServiceProvider"