JSON

Posted 4 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);

}

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.