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?
get() returns an array not an object. You can simply do json_encode($users);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With