'.$title.'';
});
HTML::macro('tab_link', function($url, $text, $active = false) {
$class = $active ? ' class="active"' : '';
return ''.$text.'';
});
HTML::macro('menu_link', function($type) {
$types = $type.'s';
$Type = ucfirst($type);
$Types = ucfirst($types);
$class = ( Request::is($types) || Request::is('*'.$type.'*')) && !Request::is('*advanced_settings*') ? ' active' : '';
$str = '
'.trans("texts.$types").'
';
return $str;
});
HTML::macro('image_data', function($imagePath) {
return 'data:image/jpeg;base64,' . base64_encode(file_get_contents(public_path().'/'.$imagePath));
});
HTML::macro('breadcrumbs', function() {
$str = '';
// Get the breadcrumbs by exploding the current path.
$basePath = Utils::basePath();
$parts = explode('?', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '');
$path = $parts[0];
if ($basePath != '/') {
$path = str_replace($basePath, '', $path);
}
$crumbs = explode('/', $path);
foreach ($crumbs as $key => $val) {
if (is_numeric($val)) {
unset($crumbs[$key]);
}
}
$crumbs = array_values($crumbs);
for ($i=0; $i';
}
}
return $str . '
';
});
Validator::extend('positive', function($attribute, $value, $parameters) {
return Utils::parseFloat($value) >= 0;
});
Validator::extend('has_credit', function($attribute, $value, $parameters) {
$publicClientId = $parameters[0];
$amount = $parameters[1];
$client = \App\Models\Client::scope($publicClientId)->firstOrFail();
$credit = $client->getTotalCredit();
return $credit >= $amount;
});
// check that the time log elements don't overlap
Validator::extend('time_log', function($attribute, $value, $parameters) {
$lastTime = 0;
$value = json_decode($value);
array_multisort($value);
foreach ($value as $timeLog) {
list($startTime, $endTime) = $timeLog;
if (!$endTime) {
continue;
}
if ($startTime < $lastTime || $startTime > $endTime) {
return false;
}
if ($endTime < min($startTime, $lastTime)) {
return false;
}
$lastTime = max($lastTime, $endTime);
}
return true;
});
Validator::extend('less_than', function($attribute, $value, $parameters) {
return floatval($value) <= floatval($parameters[0]);
});
Validator::replacer('less_than', function($message, $attribute, $rule, $parameters) {
return str_replace(':value', $parameters[0], $message);
});
}
/**
* Register any application services.
*
* This service provider is a great spot to register your various container
* bindings with the application. As you can see, we are registering our
* "Registrar" implementation here. You can add your own bindings too!
*
* @return void
*/
public function register()
{
$this->app->bind(
'Illuminate\Contracts\Auth\Registrar',
'App\Services\Registrar'
);
}
}