我想显示来自 ControllerSalarie 的 POINTAGE 和 SALARY 表数据,但它给了我这个错误
点数模型
public function salarie()
{
return $this->belongsTo('App\Salarie');
}
薪酬模式
public function pointages()
{
return $this->hasMany('App\Pointage');
}
迁移迁移 salarie_id
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('pointages', function (Blueprint $table) {
$table->integer('salarie_id')->unsigned()->after('id');
$table->foreign('salarie_id')->references('id')->on('salaries');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('pointages', function (Blueprint $table) {
$table->dropForeign(['salarie_id']);
$table->dropCulomn('salarie_id');
});
}
薪水 Controller
public function consulter()
{
$salaries=Salarie::with('pointage')->get();
$pointages = DB::table('pointages')->pluck("pointage","id")->all();
return view('salarie.consulter', compact('salaries', 'pointages'));
}
最佳答案
只需将 with('pointage')
更改为 with('pointages')
关于mysql - 调用模型 [App\Salarie] 上的未定义关系 [pointage]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56925634/