JSON

Published 2 months ago by chagouani

I have 5 table

techniciens(id, user_id,actif) 
users (nom , prenom , adresse )
tarificationtaches (id , tarif , technicien_id,tache_id , tarif) 
intervention(id , tarification_id , technicien_id....)
avis_interventions( id , intervention_id , note )

I have a web service function to display the 'tarificationtache' list with the id of technicien but i would to shown his name and the avg of 'avis_interventions'

this is my service :

 public function getTar($id){

$taches=  Tache::with("tarificationtache")->get();
return response(compact('taches'));
}

he shown like this :

{"taches":[{"id":1,"libelle_tache":"montage  porte   
  simple","Tarif":null,"metier_id":1,"deleted_at":null,"created_at":"2018-06-08 
  11:41:41","updated_at":"2018-06-08 11:41:41","tarificationtache":[]},{"id":2,"libelle_tache":"tache 
  1","Tarif":null,"metier_id":1,"deleted_at":null,"created_at":"2018-06-08 
  11:41:55","updated_at":"2018-06-08 11:41:55","tarificationtache":[]},{"id":3,"libelle_tache":"tache 
  2","Tarif":null,"metier_id":2,"deleted_at":null,"created_at":"2018-06-08 
  11:42:01","updated_at":"2018-06-08 11:42:01","tarificationtache": 
  [{"id":1,"tarif":29.55,"tache_id":3,"technicien_id":1,"deleted_at":null,"created_at":"2018-06-08 
 11:58:54","updated_at":"2018-06-08 11:58:54"}]},{"id":4,"libelle_tache":"tache 
 3","Tarif":null,"metier_id":3,"deleted_at":null,"created_at":"2018-06-08 
 12:00:15","updated_at":"2018-06-08 12:00:15","tarificationtache": 
[{"id":2,"tarif":55.12,"tache_id":4,"technicien_id":2,"deleted_at":null,"created_at":"2018-06-08 
12:00:37","updated_at":"2018-06-08 12:00:37"}, 
{"id":3,"tarif":253,"tache_id":4,"technicien_id":1,"deleted_at":null,"created_at":"2018-06-15 
23:17:23","updated_at":"2018-06-15 23:17:23"}, 
{"id":4,"tarif":28.22,"tache_id":4,"technicien_id":2,"deleted_at":null,"created_at":"2018-06-20 
17:03:32","updated_at":"2018-06-20 17:03:32"}]}]}

saying that the average rating i perform in laravel with this functin

 public function show($id)
{
    $technicien = technicien::findOrFail($id);
    $notes = $technicien->avisinterventions->pluck('note');
    $moyenne = $technicien->avisinterventions()->avg('note');
    

    $user = $technicien->user;
    $metier = $technicien->metier;
    $tarificationtache = $technicien->tarificationtache;
    $zoneintervention = $technicien->zoneintervention;


    return view('technicien.show' , compact('technicien'))->with('user',$user)- 
   >with('metier',$metier)->with('zoneintervention',$zoneintervention)- 
   >with('tarificationtache',$tarificationtache)->with('moyenne',$moyenne);

}
Vilfago

What's your question/issue ?

chagouani

@Vilfago i would like to shown the 'nom' and the avg note of technicien not the technicien_id

Vilfago

In your view technicien.show, do $technicien->name.

Or tell us where you display the id, and you wanr the name instead.

And next time choose a title which make sense... I don't see any json in your thread.

chagouani

@Vilfago i would like a json fonction to call it in android application

chagouani

Please sign in or create an account to participate in this conversation.