JSON return null 'meiter'


JSON return null 'meiter'



I have a function that displays the select id 'technicien' and he showed his name from table user and there 'metier'
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();

});



metier_tables


Schema::create('metiers', function (Blueprint $table) {
$table->increments('id');
$table->string('libelle_metier');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});



users_table


Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email');
$table->string('password');
$table->string('nom');
$table->string('prenom');
$table->string('tel');
$table->string('mobil');
$table->boolean('role')->default(0);
$table->datetime('deleted_at')->nullable();
$table->rememberToken();
$table->timestamps();
});



technicien model


public function user()
{
return $this->belongsTo(User::class);
}

public function metier()
{
return $this->belongsToMany('Appmetier','technicien_metier',
'technicien_id','metier_id');

}



metier model


public function techniciens()
{
return $this->belongsToMany('Apptechnicien','technicien_metier',
'metier_id','technicien_id');

}



** I have this function in my technicien controller**


public function GetTables() {
$techniciens = Technicien::with('user','metier')->get();

return $techniciens->map(function ($technicien) {
return [
'id' => $technicien->id,
'actif' => $technicien->actif,
'moyenne_avis' => $technicien->moyenne_avis,
'nom' => $technicien->user->nom,
'prenom' => $technicien->user->prenom,
'metier' => $technicien->metier_id,
'adresse' => $technicien->user->adresse,
];
});
}



it shown me like that


[{"id":1,"actif":1,"moyenne_avis":null,"nom":"tech
1","prenom":"frederic","metier":null,"adresse":null},
{"id":2,"actif":0,"moyenne_avis":null,"nom":"tech 2","prenom":"tech
2","metier":null,"adresse":null}]



I would like to show the list of 'metier'





.......................................
– chagou2704
21 hours ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Opening a url is failing in Swift

Exoplayer HLS doesn't show subtitle

Export result set on Dbeaver to CSV