Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未找到列:1054未知列_Php_Json_Laravel - Fatal编程技术网

Php 未找到列:1054未知列

Php 未找到列:1054未知列,php,json,laravel,Php,Json,Laravel,我有一个功能,用于显示“tarificationtaches”,其中moyenne_avis的平均值来自与干预相关的表avis干预。我有此错误 "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'interventions.tarificationtache_id' in 'where clause' (SQL: select * from `interventions` where `interven

我有一个功能,用于显示“tarificationtaches”,其中moyenne_avis的平均值来自与干预相关的表avis干预。我有此错误

"SQLSTATE[42S22]: Column not found: 1054 Unknown column      
    'interventions.tarificationtache_id' in 'where clause' (SQL: select * 
    from `interventions` 
where `interventions`.`tarificationtache_id` in (1, 2, 3, 4))
tarificationtaches\u表

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();
    });
技术参数表

 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();

    });
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();
    });
 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();
    });
avis\U干预措施表

 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();

    });
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();
    });
 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();
    });
干预措施\u表格

 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();

    });
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();
    });
 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','intervention')- 
    >get();
        $notes = $tarifications->intervention->avisinterventions- 
   >pluck('note');
        $moyenne = $tarifications->intervention()->avisinterventions()- 
   >avg('note');
        return $tarifications->map(function ($tarification) {
            return [
                'nom' => $tarification->technicien->user->nom,
                'moyenne_avis' => $tarification->intervention- 
     >avisinterventions->avg('note'),
                'tache' => $tarification->tache->libelle_tache,
                'tarif' => $tarification->tarif,
            ];
        });    



}
tarification环节模型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class tarificationtache extends Model
{
use SoftDeletes;
protected $guarded = [];
 protected $dates = ['deleted_at'];
public function tache()
{
    return $this->belongsTo(Tache::class);
}


public function technicien()
{
    return $this->belongsTo(Technicien::class);

}
public function intervention() {
    return $this->hasMany(intervention::class);
}


}

只需将外键添加到关系方法中即可

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class tarificationtache extends Model
{
   use SoftDeletes;
   protected $guarded = [];
   protected $dates = ['deleted_at'];
   public function tache()
   { 
       return $this->belongsTo(Tache::class);
   }    

   public function technicien()
   {
       return $this->belongsTo(Technicien::class);
   }

    public function intervention() 
    {
        return $this->hasMany(intervention::class, 'tarification_id');
    }
}

看起来您的
tarification链接上的关系不正确。请给我们看看你的护照code@Jerodev我已经在我的代码中添加了tarificationtache模型。我有一个错误“此集合实例上不存在属性[interference]”