Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在“选择”菜单上更改网站语言更改不起作用-MethodNotAllowedHttpException_Php_Laravel - Fatal编程技术网

Php 在“选择”菜单上更改网站语言更改不起作用-MethodNotAllowedHttpException

Php 在“选择”菜单上更改网站语言更改不起作用-MethodNotAllowedHttpException,php,laravel,Php,Laravel,我安装了这个软件包“” 我想根据选择菜单翻译网站,因此当用户在选择菜单中选择语言时,网站内容应使用上述软件包翻译为所选语言 但它不起作用,当用户以“Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in RouteCollection.php”的形式更改语言时,下面的代码将不起作用 然后我有一节课: namespace App\Http\Middleware; use Closure; class Tra

我安装了这个软件包“”

我想根据选择菜单翻译网站,因此当用户在选择菜单中选择语言时,网站内容应使用上述软件包翻译为所选语言

但它不起作用,当用户以“Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in RouteCollection.php”的形式更改语言时,下面的代码将不起作用

然后我有一节课:

namespace App\Http\Middleware;

use Closure;

class Translate
{
    protected $default = 'en';

    protected $languages = [
         'en',
         'nl',
         'fr',
    ];

    public function handle($request, Closure $next)
    {
        if($request->has('language')) {
            $lang = $request->language;
            if(array_search($lang, $this->languages) === false) {
                $lang = $this->default;
            }

            $request->session()->put('lang', $lang);
        }

        \LaravelLocalization::setLocale( $request->session()->get('lang') );

        return $next($request);
    }

}
在in kernel.php中:

  protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,  // <-- without this one, it wont work
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\Translate::class,   // <-- Add it here
        ],
        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

该错误通常与使用的错误http方法有关。请检查您提交给它的路由,该路由可能会从Route::get to PostThank更改,但与post相同。
form method="get" id="translate">
  <select name="language" class="form-control font-weight-normal text-gray" id="language" onchange="localize">
    <option value="en">English</option>
    <option value="fr">French</option>
    <option value="es">Spanish</option>
    <option>5</option>
  </select>
</form>
$(document).ready(function(){

 var myFormName = "translate";
 $('#language').on('change', function)(){

     $('#translate).submit();
  });
});