Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function toJson() on a non-object Laravel 5.0

From below code reference, I am joining the users table, user_details table and user_config table with each record similar key and no problem with that (it works), yet when I'm trying to convert the result records to json array, it gives me this error

Call to a member function toJson() on a non-object

public function get_users_table(){
       $users = DB::table('users')
        ->join('user_details', 'users.id', '=', 'user_details.id')
        ->join('user_config', 'users.id', '=', 'user_config.id')
        //->select('users.*', 'contacts.phone', 'orders.price')
        ->get()->toJson();

       return response()->json(['success' => true, 'users' => $users]);
    }

Any ideas, help?

like image 464
Juliver Galleto Avatar asked Oct 04 '15 16:10

Juliver Galleto


1 Answers

get() returns an array not an object. You can simply do json_encode($users);

like image 124
changepicture Avatar answered Sep 27 '22 21:09

changepicture