所以我在我的办公室页面上有这个Editform,问题是当我按下编辑按钮时它会说这个
Missing required parameters for [Route: editoffice] [URI: building/{id}/offices/{office_id}/edit]. (View: C:\xampp\htdocs\Eguide\resources\views\editoffice.blade.php)
路线
Route::get('building/{id}/offices/{office_id}/edit', 'OfficeController@edit')->name('editofficeform');
Route::post('building/{id}/offices/{office_id}/edit', 'OfficeController@update')->name('editoffice');
Building.blade.php
这是编辑按钮的代码
<a href="{{route('editofficeform', ['id'=>$building->id, 'office_id'=>$office->id])}}" class="btn btn-success btn-sm">Edit</a>
OfficeController.php
public function edit(Request $request, $id)
{
$office_id = $request->get('office_id');
$office = Office::find($office_id);
return view('editoffice')->withOffice($office)->with('id',$id);
}
public function update(Request $request, $id)
{
$office = Office::find($id);
$office->name =$request->officename;
$office->floor = $request->floor;
$office->update();
\Session::flash('building_flash', 'Updated successfully!');
return redirect()->back();
}
editoffice.blade.php
@extends('layouts.main')
@section('title', 'Create an Office')
@section('content')
{!! Form::open(array('route' => ['editoffice', $id], 'class' => 'form')) !!}
<div class="container">
<div class="form-group">
{!! Form::label('Office Name') !!}
{!! Form::text('officename', $office->name, array('required',
'class'=>'form-control',
'placeholder'=>'Office Name')) !!}
</div>
<div class="form-group">
{!! Form::label('Office Floor') !!}
{!! Form::text('floor', $office->floor, array('required',
'class'=>'form-control',
'placeholder'=>'Office Floor')) !!}
</div>
<div class="form-group">
{!! Form::submit('Update Office',
array('class'=>'btn btn-primary')) !!}
<a href="{{ route('building', ['id' => $id] ) }}" class="btn btn-default">Back</a>
</div>
{!! Form::close() !!}
@endsection
我的代码出了什么问题?
答案 0 :(得分:2)
将表单更改为:
{!! Form::open(array('route' => ['editoffice', [$id, $office->id]], 'class' => 'form')) !!}
另外,将edit
和update
方法更改为:
public function edit($id, $office_id) {
$office = Office::find($office_id);
return view('editoffice', compact('office', 'id'));
}
public function update(Request $request, $id, $office_id)