I'm trying to select multiple columns and avoid duplicate values in these columns with Laravel. Here is my data:
id, name, job, department
[1, "Jane Doe", "worker", "departmentA"]
[2, "Adam Smith", "manager", "departmentB"]
[3, "Machiavelli", "worker", "departmentA"]
[4, "Rousseau", "worker", "departmentC"]
I want to get job and department without duplicate data. So I want this result:
[["worker", "manager"], ["departmentA", "departmentB", "departmentC"]]
I'm trying to get it with model like that:
$users = Users::all();
$user_fields = $users->pluck("job", "department")->toArray();
return $user_fields;
But it's not working. How can I do it?