mouzak
329
7
Laravel

Foreign key

Posted 3 months ago by mouzak

hi,how to automatically retrieve the primary key from the table 'salaries'. knowing it's foreign key in the table'paie'. paie model

namespace App;

use Illuminate\Database\Eloquent\Model;

class paie extends Model { public function relationsalaires() { return $this->belongsTo('App\salaries', 'idsalaries'); }

protected $table = 'paie';

}

salaries model

namespace App;

use Illuminate\Database\Eloquent\Model; class salaries extends Model{

public function relationPaie(){
    return $this->hasOne ('App\paie');
}

}

Please sign in or create an account to participate in this conversation.