我想显示ControllerSalarie的POINTAGE和SALARY表数据,但这给了我这个错误
积分模型
public function salarie()
{
return $this->belongsTo('App\Salarie');
}
Salarie模型
public function pointages()
{
return $this->hasMany('App\Pointage');
}
migration migration 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');
});
}
SalarieController
public function consulter()
{
$salaries=Salarie::with('pointage')->get();
$pointages = DB::table('pointages')->pluck("pointage","id")->all();
return view('salarie.consulter', compact('salaries', 'pointages'));
}
答案 0 :(得分:4)
只需将with('pointage')
更改为with('pointages')
答案 1 :(得分:2)
更改:
$salaries=Salarie::with('pointage')->get();
收件人:
$salaries=Salarie::with('pointages')->get();