在laravel的show函数中,在我的控制器中,我希望获取在浏览器show中显示的id,当我浏览它时,它显示如下。
现在如何将学校表的ID保存到申请的school_id中。
public function store(Request $request, School $school)
{
$school_id = $request->get($school->id);
$requisition = new Requisition();
$requisition->user_id = auth()->user()->id;
$requisition->school_id = $school_id;
$requisition->type = $request->application;
$requisition->status = 0;
$requisition->approved = 0;
$requisition->save();
return redirect(route('school.index'));
}
型号
class Requisition extends Model
{
public function schools()
{
return $this->belongsTo(School::class, 'school_id');
}
}
create.blade.php
<form action="{{ route('requisitions.store')}}" method="post">
{{ csrf_field() }}
<div class="radio">
<label for="school">School</label>
<input type="radio" value="1" id="school" name="application">
<br>
<label for="equipment">Equipment</label>
<input type="radio" value="2" id="equipment" name="application">
<br>
<label for="level">Level</label>
<input type="radio" value="3" id="level" name="application">
<br>
<label for="place">Place</label>
<input type="radio" value="4" id="place" name="application">
<br>
<label for="tax">Tax</label>
<input type="radio" value="5" id="tax" name="application">
<br>
<label for="reactivation">Reactivation</label>
<input type="radio" value="6" id="reactivation" name="application">
<br>
<button type="submit" class="btn-warning btn">Send</button>
</div>
</form>
我确实已经在create函数中发送过消息。
public function create()
{
$school = School::all();
return view('Admin.requisitions.create', compact('school'));
}