Skip to content

Instantly share code, notes, and snippets.

@vluzrmos
Last active Aug 29, 2015
Embed
What would you like to do?
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