lundi 21 mai 2018

404 NOT FOUND when use locales

I am using middlleware to switch between languages English an Arabic

<?php

namespace App\Http\Middleware;

use Closure;

class ApplyLocale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $segments = collect($request->segments());

        $locale = $segments->first();

        if (! in_array($locale, config('app.locales'))) {
            $locale = 'ar';
            app()->setLocale($locale);
            $segments->prepend($locale);

            return redirect($segments->implode('/'));
        }

        app()->setLocale($locale);

        return $next($request);
    }
}

and in helper.php I use this to switch between

/**
 * @return string
 */
function switchLocaleUrl()
{
    $locale = config('app.locale');

    if ($locale === 'ar') {
        return '/en/' . collect(Request::segments())->splice(1)->implode('/');
    }
    return '/ar/' . collect(Request::segments())->splice(1)->implode('/');
}

and in view I use :

  <li><a href=""><i class="hvr-float-shadow"></i> </a></li> 

but when I go to url localhost/myproject/ar the error 404 NOT FOUND happened



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire