I have two table Users and ratings,.A User can give rating to consultant, My Rating table look like below
User_id | consultant_id | rating
---------------------------------
1 1 2
---------------------------------
2 1 3
---------------------------------
3 1 1
---------------------------------
4 1 1
This how my table looks like
My controller:
public function searchConsultants(Request $request)
{
$location = $request->get('location');
$data = Consultant::where('location','LIKE','%'.$location.'%')->with('ratings')->get();
return response()->json($data);
}
Im using ajax get method to diplay the data, here is my js file
$.each(data, function(index) {
str +="<tr><td>"+data[index].id+"</td>
<td>"+data[index].cunsultant_name+"</td>
<td>"+data[index].contact_number+"</td>
<td>"+data[index].ratings[index].rating_for_manager+"</td><td>"+data[index].location+"</td></tr>";
});
When I click search consultant button I should get consultant details with average ratings.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire