hi, how to resolve this error please? No query results for model [App\salaries] id
controller
$data['sala'] = salaries::findOrFail($id) ->relationPaie()->save(new paie());
when i do $data['sala'] = salaries::findOrFail('8') ->relationPaie()->save(new paie());
the request is executed but when i change the number by a variable i got an error.
@FTIERSCH - $id is primary key in table 'salaries' who have model 'salaries'
relationPaie is a methode
public function relationPaie(){
return $this->hasOne (paie::class);
}
I hope it's a little understandable
@FTIERSCH - I want to save $ id table 'salaries' in table 'paies' as foreign key.
the variable in the controller comes from the 'salaries' table. I tried to see if it will be registered in the 'paie' table and it is registered by cons if I replace it with $ id the error occurs
@MOUZAK - The error says that in the salaries table there is no entry with the id that has the value of your variable $id... So can you show the complete controller method?
@FTIERSCH - it's ok but I want the insertion is done each time there is a new entry in the table 'salaries'. I thought doing $ id = DB :: table ('salaries') -> id;
:: findOrFail ($ id) but it does not work.
@FTIERSCH - so I have to remove $id = 5; ::findOrFail($id) in the controller.
model
class salaries extends Model{
public function relationPaie(){
return $this->hasOne (paie::class);
}
public static function boot() {
parent::boot();
self::created(function ($model) {
$model->relationPaie()->save(new paie());
});