1

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?

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
Devmasta
  • 513
  • 2
  • 14
  • 38

1 Answers1

2

You've forgot to declare this variable:

public function findUser(Request $request) {
    $return_array = [];
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279