PHP code example of tyler36 / laravel-helper-macros

1. Go to this page and download the library: Download tyler36/laravel-helper-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/ */

    

tyler36 / laravel-helper-macros example snippets


$collect = collect([1, 2, 3])
    ->pipe(function ($data) {
        return $data->merge([4, 5, 6]);
    });

collect($items)
  ->filter(function() {
     ...
   })
  ->dd()

$items = collect([]);
$items->ifEmpty(function(){
    abort(500, 'No items');
});

$errors = collect(['Something went wrong']);
$errors->ifAny(function(){
    abort(500, 'There was at-least 1 problem');
});

$emailLookup = $employees->mapToAssoc(function ($employee) {
    return [$employee['email'], $employee['name']];
});

response()->success($data);

response()->error('Not authorized!', 403);