I have this eloquent model query
public function getemployee(){
$id = $_POST['id'];
$employees = mot_users::where("branch_no", $id)->lists('user_no', 'lastname', 'firstname');
return response()->json(['success' => true, 'employees' => $employees]);
}
the problem is this "->lists();" can only handle 2 columns which sent as a json response (seen through console, only 2 selected columns out of 3 is sent). How can I send 3 columns or more than 2 columns in the "->list()" or is there any alternative eloquent model query other than using "->list()" if its impossible?
To do this, just do a
$employees = mot_users::where("branch_no", $id)->get(array('user_no','lastname','firstname'))->toArray();
That should do the trick.
Note that if your model object has a relationship and this column relationship isn't part of what you try to ->get
you can't get an error.
Note 2 that here you're using the good ol' $_POST
, you should consider using the proper Request object as seen in the doc.