laravel与离子:500(内部服务器错误) [英] laravel with ionic :500 (Internal Server Error)

查看:245
本文介绍了laravel与离子:500(内部服务器错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么毛病我下面code? CAZ它总是显示:
500(内部服务器错误)
我不知道为什么,希望有人能帮助,谢谢...

is there anything wrong with my following code? caz it always shows: 500 (Internal Server Error) I do not know why and hope anyone can help,thanks...

我已经寻找了一天,但没有任何解决方案。我这么想吗?
而且我在使用离子做移动应用程序。

I have searched for a day but without any solution. Am i missing something? And i am using ionic to do the mobile application.

//控制器

 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)

//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();                   
    }
  }

非常感谢!

推荐答案

这Laravel的版本,您使用的?如果打开调试,什么是500错误给出的消息?

Which version of Laravel are you using? If you turn on debugging, what is the message given for the 500 error?

我的猜测是,你的请求变量的位置指标未设置。 Laravel提供检索请求输入,已经占指标这可能会或可能不会进行设置,所以你应该使用它。

My guess would be that the 'location' index of your request variable is not set. Laravel provides a much better way of retrieving the request input, which already accounts for indexes which may or may not be set, so you should use that.

总之,假设你在Laravel 5+,这样做在你的控制器:

Anyway, assuming you're on Laravel 5+, do this in your controller:

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:

And the same thing, but for 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'));
}

这篇关于laravel与离子:500(内部服务器错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆