Skip to content

Instantly share code, notes, and snippets.

View hamzaali00001's full-sized avatar

Hamza Ali hamzaali00001

View GitHub Profile
<?php
if (!function_exists('human_file_size')) {
/**
* Returns a human readable file size
*
* @param integer $bytes
* Bytes contains the size of the bytes to convert
*
* @param integer $decimals
<?php
if (!function_exists('human_file_size')) {
function human_file_size($bytes, $decimals = 2)
{
// ...
}
}
"autoload": {
"files": [
"app/Helpers/Helper.php"
],
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
public function register()
{
$file = app_path('Helpers/Helper.php');
if (file_exists($file)) {
require_once($file);
}
}
public function register()
{
foreach (glob(app_path() . '/Helpers/*.php') as $file) {
require_once($file);
}
}
<?php
Route::get('/', function () {
return human_file_size(1024*1024);
});
function tap($value, $callback)
{
$callback($value);
return $value;
}
<?php
return tap($photo, function($photo) {
$photo->validated = true;
$photo->save();
});
function tap($value, $callback = null)
{
if (is_null($callback)) {
return new HigherOrderTapProxy($value);
}
$callback($value);
return $value;
}
<?php
$photo = App\Photo::find(1);
return tap($photo)->update([
'validated' => 'true',
])