Laravel 5 localization: exclude / public / directory

I am trying to implement localization in my Laravel 5 project and I am having a problem. The middleware that I put in to catch the tongue looks like this:

<?php namespace App\Http\Middleware; use Closure; use Illuminate\Routing\Redirector; use Illuminate\Http\Request; use Illuminate\Foundation\Application; use Illuminate\Contracts\Routing\Middleware; class Language implements Middleware { public function __construct(Application $app, Redirector $redirector, Request $request) { $this->app = $app; $this->redirector = $redirector; $this->request = $request; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // Make sure current locale exists. $locale = $request->segment(1); if ( ! array_key_exists($locale, $this->app->config->get('app.locales'))) { $segments = $request->segments(); $segments[0] = $this->app->config->get('app.fallback_locale'); return $this->redirector->to(implode('/', $segments)); } $this->app->setLocale($locale); return $next($request); } } 

kernel.php:

 protected $middleware = [ 'App\Http\Middleware\Language', 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', 'Illuminate\Cookie\Middleware\EncryptCookies', 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware\ShareErrorsFromSession', 'App\Http\Middleware\VerifyCsrfToken', ]; 

routeserviceprovider.php:

 public function map(Router $router, Request $request) { $locale = $request->segment(1); $this->app->setLocale($locale); $router->group(['namespace' => $this->namespace, 'prefix' => $locale], function($router) { require app_path('Http/routes.php'); }); } 

It works fine, except for one. When I try to go to http://0.0.0.0/public/css/images/myimage.png , it replaces public with en , and if I go to /en/public , it tells me that the route does not exist.

Any help to exclude a public directory from this or implement localization in a more efficient way that is not related to middleware?

+5
source share
1 answer

Your image must be in a public folder, and the public folder must be public and configured in Apache.

You must correct your configuration in order to access the image using the following URL: http://0.0.0.0/css/images/myimage.png

And this will happen when public is the public folder you set up.

+1
source

All Articles