hey everybody ! i need some help so , i have 3 tables (" vehicules ", "conducteurs") and ("affectation") this table present the relationshape between
(" vehicules " AND "conducteurs") i set in this table the id of those tables the problem is when i want select in view some informations of those tables i use this in view
@foreach ($Conducteurs as $categorie)
<tr>
<td>{{$categorie->vehicules->test }} </td>
<td>{{$categorie->conducteurs->test }} </td>
</tr>
@endforeach
a try this to :
@foreach ($Conducteurs as $categorie)
<tr>
@foreach ($Conducteurs as $categorie)
<td>{{$categorie->vehicules()->test }} </td>
@endforeach
@foreach ($Conducteurs as $categorie)
<td>{{$categorie->conducteurs()->test }} </td>
@endforeach
</tr>
@endforeach
this is my controller :
public function ShowAffectation(){
if (Auth::check()) { // user is an admin
$affectation=DB::table('affectations')
->join('conducteurs', 'affectations.NumeroConducteur', '=', 'conducteurs.NumeroConducteur')
->join('vehicules', 'affectations.NumeroVéhicule', '=', 'vehicules.NumeroVéhicule')
->get();
$arr=Array( 'affectation'=>$affectation);
return view('Operations/affectations',$arr) ;
}
return view('auth/login-admin');// user is a guest
}
the tables:
//conducteurs
public function up()
{
Schema::create('conducteurs', function (Blueprint $table) {
$table->increments('NumeroConducteur');
$table->integer('NumeroPermis');
$table->string('Nom');
$table->string('Prenom');
$table->date('DateNaissance');
$table->string('Adresse');
$table->string('SituationFamiliale');
$table->string('Genre');
$table->date('AnneeObtention');
$table->string('WilayaObtention');
$table->timestamps();
});
}
//affectations
public function up()
{
Schema::create('affectations', function (Blueprint $table) {
$table->increments('ID_Affectation');
$table->integer('NumeroVéhicule')->unsigned();
$table->foreign('NumeroVéhicule')->references('NumeroVéhicule')->on('vehicules');
$table->integer('NumeroConducteur')->unsigned();
$table->foreign('NumeroConducteur')->references('NumeroConducteur')->on('conducteurs');
$table->timestamps();
});
}
//véhicules
public function up()
{
Schema::create('vehicules', function (Blueprint $table) {
$table->increments('NumeroVéhicule');
$table->integer('NumeroSequenceMatricule');
$table->string('Wilaya');
$table->date('AnneeCirculation');
$table->string('Marque');
$table->string('Modele');
$table->string('Couleur');
$table->timestamps();
});
}
AND finaly the models :
//conducteurs
protected $table="conducteurs";
public function vehicule(){
return $this->belongsTo('App\Affectation');
}
//véhicules
protected $table="vehicules";
public function vehicule(){
return $this->belongsTo('App\Affectation');
}
//affectations
protected $table="affectations";
public function conducteur(){
return $this->hasMany('App\Conducteur','NumeroConducteur');
}
public function vehicule(){
return $this->hasMany('App\Vehicule','NumeroVéhicule');
}
ALL this doesn't Work ! :/