Created
February 25, 2017 16:56
-
-
Save hewerthomn/267f00da6b644a40bd1025a07f374d28 to your computer and use it in GitHub Desktop.
Como definir o locale pt_BR no Laravel 5.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// config/app.php | |
/* ... */ | |
/** | |
* PHP Locale | |
*/ | |
'phplocale' => ['pt_BR', 'pt_BR.UTF-8'], | |
/* ... */ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/Http/Kernel.php | |
/* ... */ | |
protected $middleware = [ | |
/* ... */ | |
\App\Http\Middleware\LocaleSetup::class, | |
/* ... */ | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/Http/Middleware/LocaleSetup.php | |
namespace App\Http\Middleware; | |
use Closure; | |
class LocaleSetup | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$phplocale = config('app.phplocale'); | |
// descomente se for salvar o locale na sessão | |
// if(session()->has('lang')) { | |
// app()->setLocale(session()->get('lang')); | |
// $phplocale = session()->get('locale'); | |
// } | |
setlocale(LC_TIME, $phplocale); | |
return $next($request); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// routes/web.php | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register web routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| contains the "web" middleware group. Now create something great! | |
| | |
*/ | |
Route::get('/', function () { | |
$dia = date('d'); | |
$ano = date('Y'); | |
$diaSemana = ucwords(Carbon\Carbon::instance(new DateTime)->formatLocalized('%A')); | |
$mes = ucwords(Carbon\Carbon::instance(new DateTime)->formatLocalized('%B')); | |
return "{$diaSemana}, {$dia} de {$mes} de {$ano}"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment