2016-03-21 15 views
1

私の次のコードに何か問題はありますか? 500(内部サーバーエラー) 私は、私は一日のためではなく、すべてのソリューションなしで検索しましたおかげで...laravel with ionic:500(内部サーバーエラー)

、なぜ知っていると誰でも役立つことを願っていない:それは常に示しCAZ。何か不足していますか? そして私はionicを使ってモバイルアプリケーションを行っています。

//コントローラ

public function touristsData(){//get 
    $postdata = file_get_contents("php://input"); 
    $request = json_decode($postdata,true); 
    $location = $request['location']; 
    if(empty($location) != true){ 
      $tourists = User::where('block','0') 
         ->where('location', $location) 
         ->orderBy('updated_at', 'desc') 
         ->get();     
    }else{ 
      $tourists = User::where('block','0') 
         ->orderBy('updated_at', 'desc') 
         ->get();   
    } 
    return View::make('frontend.data.touristsData',array('tourists'=>$tourists)); 
} 

//app.js(angularjs)

 $scope.submitForm = function(){ 
    if($scope.filter.want == 'company'){ 
      $http({ 
       method : 'POST', 
       url  : './touristsData', 
       beforeSend: function (xhr) { 
          var token = document.getElementById('token').getAttribute('content');        
          if (token) { 
           return xhr.setRequestHeader('X-CSRF-TOKEN', token); 
          } 
       },     
       data : { 
        'location': $scope.filter.location 
       }, 
       headers : {'Content-Type': 'application/x-www-form-urlencoded'} 
      }) 
      .success(function(data){ 
       $scope.tourists = data; 
      });  
      $scope.modal.hide();     
    } 
    } 

多くの感謝!

答えて

1

あなたはどのバージョンのLaravelを使用していますか?デバッグをオンにした場合、500エラーのメッセージは何ですか?

あなたのリクエスト変数の 'location'インデックスが設定されていないと思います。 Laravelはもっと良い方法を提供していますretrieving the request inputは既に設定されているかもしれないし、そうでないかもしれないインデックスを占めているので、あなたはそれを使うべきです。とにかく

、お使いのコントローラでこれを行う、あなたはLaravel 5+にしていると仮定すると:

public function touristsData() 
{ 
    $query = User::where('block','0'); 

    if (request()->has('location')) { 
     $query->where('location', request('location')); 
    } 

    $tourists = $query->orderBy('updated_at', 'desc')->get(); 

    return view('frontend.data.touristsData', compact('tourists')); 
} 

そして、同じことが、Laravel 4.2:

public function touristsData() 
{ 
    $query = User::where('block','0'); 

    if (Input::has('location')) { 
     $query->where('location', Input::get('location')); 
    } 

    $tourists = $query->orderBy('updated_at', 'desc')->get(); 

    return View::make('frontend.data.touristsData', compact('tourists')); 
} 
+0

新を投稿しないでください質問 - 代わりにこれを編集してください。 –

+0

遅れて申し訳ありません。なぜコンパクト(「観光客」)を使っていますか? – franklee

+0

'array( 'touristists => $ touristists)'を呼ぶのと同じです。 http://php.net/manual/en/function.compact.php –

関連する問題