NathanGeerinck /
laravel-newsletter
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Middleware; |
||||
| 4 | |||||
| 5 | use Closure; |
||||
| 6 | use Illuminate\Support\Facades\Auth; |
||||
| 7 | |||||
| 8 | class LocaleMiddleware |
||||
| 9 | { |
||||
| 10 | protected $languages = ['en', 'nl']; |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * Handle an incoming request. |
||||
| 14 | * |
||||
| 15 | * @param \Illuminate\Http\Request $request |
||||
| 16 | * @param \Closure $next |
||||
| 17 | * @return mixed |
||||
| 18 | */ |
||||
| 19 | public function handle($request, Closure $next) |
||||
| 20 | { |
||||
| 21 | if (Auth::check()) { |
||||
| 22 | $lang = Auth::user()->preferences['language']; |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 23 | |||||
| 24 | app()->setLocale($lang); |
||||
|
0 ignored issues
–
show
The method
setLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 25 | } else { |
||||
| 26 | app()->setLocale(env('APP_LOCALE')); |
||||
| 27 | } |
||||
| 28 | |||||
| 29 | return $next($request); |
||||
| 30 | } |
||||
| 31 | } |
||||
| 32 |