php - laravel 5.2 ajax controller switch language internal server error -


i'm trying create ajax controller switch locate, here code:

frontend jquery :

<script language="javascript"> $( "#lang" )   .change(function () {         $.ajax({           method: "post",           url: "{{ url('/lang') }}",           headers: {                 'x-csrf-token': $('meta[name="csrf-token"]').attr('content')           },           data: { name: "john", location: "boston" }         })           .done(function( msg ) {             alert( "data saved: " + msg );         });   }) </script> 

controller:

namespace app\http\controllers;  use illuminate\http\request;  use app\http\requests; use app\http\controllers\controller;  class langcontroller extends controller {     //     public function lang () {          /*$rules = [             'language' => 'in:en,zh-tw' //list of supported languages of application.         ];*/          app::setlocale('zh-tw');          return 'success';     } } 

route:

route::post('lang', 'langcontroller@lang'); 

the result internal server error 500, app::setlocale('zh-tw'); run in other non-ajax controller, know what's wrong that?

try using \app::setlocale('zh-tw');

because want use illuminate\support\facades\app::class compiler looking app class in current namespace. can import class using use app alias. more on namespace here


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -