-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new middleware to dynamically use current locale as base-view-p…
…ath (#446) * Added new middleware to dynamically use current locale as base-view-path * Updated Readme
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationViewPath.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
use Closure; | ||
use Illuminate\Support\Facades\View; | ||
use Illuminate\Http\Request; | ||
|
||
class LaravelLocalizationViewPath extends LaravelLocalizationMiddlewareBase | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) { | ||
|
||
// If the URL of the request is in exceptions. | ||
if ($this->shouldIgnore($request)) { | ||
return $next($request); | ||
} | ||
|
||
$app = app(); | ||
|
||
$currentLocale = app('laravellocalization')->getCurrentLocale(); | ||
$viewPath = resource_path('views/' . $currentLocale); | ||
|
||
// Add current locale-code to view-paths | ||
View::addLocation($viewPath); | ||
|
||
return $next($request); | ||
} | ||
|
||
} |
Is it correct path? Maybe it's should be Mcamara\LaravelLocalization\Middleware?