У меня есть функция, которая отображает список 'tarificationtaches'. Я хотел бы добавить среднее значение, чтобы получить среднее значение 'techniciens' moyenne_avis из таблиц avis_intervention, где "vention.technicien_id "=" tarificationtaches.techncien_id ", в этой моей схеме .
taches_table
public function up()
{
Schema::create('taches', function (Blueprint $table) {
$table->increments('id');
$table->string('libelle_tache');
$table->float('Tarif', 8,2)->nullable();
$table->integer('metier_id')->unsigned();
$table->foreign('metier_id')->references('id')->on('metiers');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
}
tarificationtaches_tables
Schema::create('tarificationtaches', function (Blueprint $table) {
$table->increments('id');
$table->float('tarif', 8,2);
$table->integer('tache_id')->unsigned();
$table->foreign('tache_id')->references('id')->on('taches');
$table->integer('technicien_id')->unsigned();
$table->foreign('technicien_id')->references('id')->on('techniciens');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
techniciens_tables
Schema::create('techniciens', function (Blueprint $table) {
$table->increments('id');
$table->boolean('actif')->default(1);
$table->float('moyenne_avis')->nullable();
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
avis_interventions_tables
Schema::create('avis_interventions', function (Blueprint $table) {
$table->increments('id');
$table->string('qualité');
$table->integer('nbr_heure');
$table->string('service');
$table->float('note', 1,1);
$table->integer('client_id')->unsigned();
$table->foreign('client_id')->references('id')->on('clients');
$table->integer('intervention_id')->unsigned();
$table->foreign('intervention_id')->references('id')->on('interventions');
$table->timestamps();
});
interventions_tables
Schema::create('interventions', function (Blueprint $table) {
$table->increments('id');
$table->date('date_intervention')->nullable();
$table->string('description');
$table->dateTime('duree_prevu');
$table->boolean('statut');
$table->integer('technicien_id')->unsigned();
$table->foreign('technicien_id')->references('id')->on('techniciens');
$table->integer('tarification_id')->unsigned();
$table->foreign('tarification_id')->references('id')->on('tarificationtaches');
$table->integer('client_id')->unsigned();
$table->foreign('client_id')->references('id')->on('Clients');
$table->timestamps();
});
это моя функция
public function getTar(){
$tarifications = tarificationtache::with('technicien')->get();
return $tarifications->map(function ($tarification) {
return [
'nom' => $tarification->technicien->user->nom,
'moyenne_avis' => $tarification->technicien->moyenne_avis,
'tache' => $tarification->tache->libelle_tache,
'tarif' => $tarification->tarif,
];
});
}
это показано так
[{"nom":"tech 1","moyenne_avis":null,"tache":"tache 2","tarif":29.55},
{"nom":"tech
2","moyenne_avis":null,"tache":"tache 3","tarif":55.12},{"nom":"tech
1","moyenne_avis":null,"tache":"tache 3","tarif":253},{"nom":"tech
2","moyenne_avis":null,"tache":"tache 3","tarif":28.22}]