Skip to content

Instantly share code, notes, and snippets.

@relliv
Created January 27, 2022 16:02
Show Gist options
  • Select an option

  • Save relliv/cd6342c81114266848c1059aba7324e1 to your computer and use it in GitHub Desktop.

Select an option

Save relliv/cd6342c81114266848c1059aba7324e1 to your computer and use it in GitHub Desktop.
Laravel Carbon localize middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Carbon\Carbon;
class Localize
{
public function __construct(
private Application $app,
) {}
public function handle(Request $request, Closure $next)
{
Carbon::setLocale($this->app->getLocale());
return $next($request);
}
}
@relliv
Copy link
Author

relliv commented Mar 12, 2022

Actually, we have to define in AppServiceProvider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment