1. Go to this page and download the library: Download zlt/lara-calls 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/ */
zlt / lara-calls example snippets
return [
/*
* Define your eloquent builder class so that you can use custom Eloquent macros provided by package.
*/
'builder' => \Illuminate\Database\Eloquent\Builder::class,
/*
* You may customize which macros you don't want to use.
* Only macros provided below will not be registered.
* Available Macros are 'onlyValues','pluckMultiple','updateOrCreateWhen','sortInValue','sortInValueDesc','groupAndSortBy','groupAndSortByDesc','calc_exec_time','validation'.
*/
'exclude_macros' => [],
];
//$collection->validation(array|Closure $rulesOrClosure)->onSuccess(Closure $closure)->onError(Closure $closure);
$collection = collect(['name'=>'John','email'=>'[email protected]']);
$collection->validation(['name'=>'string','email'=>'email'])
->onSuccess(function($collection){
// This will be processed
return $collection;
})->onError(function($messageBag){
// This will be skipped
return $messageBag->toArray();
});
$collection = collect(['name'=>'John','email'=>'email']);
$collection->validation(['name'=>'string','email'=>'email'])
->onSuccess(function($collection){
//This step will be skipped.
return $collection;
})->onError(function($messageBag){
return $messageBag->toArray();
}); // [ "email" => [ "The email must be a valid email address.", ], ]
$collection->validation(function($collection){
return false; //Return type must be 'boolean'.Otherwise, it will always return false.})
->onSuccess(function($collection){
//This step will be skipped.
return $collection;
})->onError(function(){
//Perform some process after failing validation
});