dongyong5255 2016-10-21 12:12
浏览 493
已采纳

Laravel 5:未定义的变量return_array [重复]

I'm trying to get data with ajax call, and after sending the ajax call i want to store data in array, but I'm getting this error when I open the page.

Undefined variable: return_array

My function

public function findUser(Request $request) {
    $findUserInput = $request->get('name');
    $user = DB::table('users')
        ->where('name', $findUserInput)
        ->first();

    $data =  DB::select("SELECT * FROM users WHERE name='$user'");

    foreach ($data as $da) {
        $return_array[] = $da;
    } 

    return $return_array;      
}

Any ideas?

</div>
  • 写回答

1条回答 默认 最新

  • dsx666666 2016-10-21 12:13
    关注

    You've forgot to declare this variable:

    public function findUser(Request $request) {
        $return_array = [];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?