以下是我的关系。
SubmitApplication.php
public function requisition()
{
return $this->hasMany(Requisition::class);
}
Requisition.php
public function submitApplication()
{
return $this->belongsTo(SubmitApplication::class);
}
我的刀片
<form class="btn-group" action="{{ route('requisitions.update', ['id' => $requisition->id]) }}" method="post">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-success btn-xs">تایید</button>
</form>
RequisitionController.php
public function update(Request $request, SubmitApplication $submitApplication)
{
$submitApplication->approved = 1;
$submitApplication->save();
return redirect()->back();
}
对于请购单表:
public function up()
{
Schema::create('requisitions', function (Blueprint $table) {
$table->increments('id');
$table->integer('school_id')->unsigned();
$table->string('type');
$table->string('status');
$table->string('date');
$table->timestamps();
$table->foreign('school_id')->references('id')->on('schools');
});
}
对于submit_applications表:
public function up()
{
Schema::create('submit_applications', function (Blueprint $table) {
$table->increments('id');
$table->integer('requisition_id')->nullable()->unsigned();
$table->integer('school_id')->nullable()->unsigned();
$table->integer('approved')->nullable(true);
$table->string('application')->nullable(true);
$table->timestamps();
$table->foreign('requisition_id')->references('id')->on('requisitions');
$table->foreign('school_id')->references('id')->on('schools');
});
}
当我点击已批准的按钮时。它补充道。 id不想添加
也许我做错了?
答案 0 :(得分:0)
在RequisitionController.php中,您必须先使用save方法检索模型。
$submitApplication = SubmitApplication ::find($request['id']);