json

Published 2 months ago by chagouani

I have 3 table

techniciens(id, user_id,actif , moyenne_avis) 
users (nom , prenom , adresse )
tarificationtaches (id , tarif , technicien_id,tache_id , tarif) 

I have a function to display the 'tarificationtache' list with the 'id' of technicien but i would to shown his 'nom' and 'moyenne_avis' group by (tache_id)

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"}]}]}
biishmar

@chagouani just return the taches it automatically become json

return $taches;
chagouani

@biishmar when i make return $taches; he shown me like this

[{"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"}]}]

but me i would like to shown the "nom" of "techniciens" from table "users" not the technicien_id from tarification

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