My table is constituted as follows:
╔════════════════════════╗
║ USER ║
╠═══════════╦════════════╣
║ Id ║ Integer ║
║ Name ║ String ║
║ Address ║ String ║
╚═══════════╩════════════╝
I have some data already stored in the database, exp:
╔═══════════╦═══════════╦═══════════════╗
║ Id ║ Name ║ Address ║
╠═══════════╬═══════════╬═══════════════╣
║ 1 ║ Marcelo ║ Rua A ║
║ 2 ║ Ferdinand ║ Rua B ║
║ 3 ║ Marcelo ║ Rua A ║
╚═══════════╩═══════════╩═══════════════╝
In my controller I have the following method:
public function getListUsers()
{
$users = DB::table("users")->pluck('Name','Address');
echo json_encode($LatLng);
return;
// return response()->json($users);
}
When I display the route that invokes the controller function, it displays the following array:
{"Marcelo": "Street A", "Ferdinand": "Street B"}
I tried to run the following:
DB::enableQueryLog();
$users= DB::table("users")
->pluck("name","address");
print_r(
DB::getQueryLog()
);
In the log, the select executed is as follows:
select 'user', 'address' from 'user'
And if I run the same select in my database, it brings me the correct data, which should be something like:
[{"name": "Marcelo", "Address": "Street A"}, {"name": "Ferdinand", "Address" , "Address": "Street A"}]