Skip to content

Instantly share code, notes, and snippets.

@vluzrmos
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vluzrmos/ad29ff6c68b0f8d3d76d to your computer and use it in GitHub Desktop.
Save vluzrmos/ad29ff6c68b0f8d3d76d to your computer and use it in GitHub Desktop.
Laravel 5.1 Helpers
<?php
if (!function_exists('faker')) {
/**
* Generate or get a faker localized instance
* @param locale $l
* @example
* <code>
* faker()->name; //will use app locale
* faker('pt_BR')->name;//change locale to pt-br
* faker()->email; //now the locale is back to default (app.locale or en_US)
* </code>
* @return \Faker\Generator
*/
function faker($l = null)
{
static $faker, $locale;
if (!$faker or (!$l and $l != $locale)) {
$faker = \Faker\Factory::create($l ?: config('app.locale'));
$locale = $l;
}
return $faker;
}
}
if (!function_exists('rksort')) {
/**
* Sort an associative array by key recursively
*
* @param array &$array
* @return bool
*/
function rksort(&$array)
{
foreach ($array as &$value) {
if (is_array($value)) {
rksort($value);
}
}
return ksort($array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment