【发布时间】:2016-07-04 06:07:22
【问题描述】:
我不知道这个错误是从哪里来的。尝试更新记录时出现此错误。它可以正常工作并更新到我的数据库中,但出现此错误。它说那错过了我的参数中的某些内容。我认为我的错误是return redirect()->route('account.show');,当我在更新后尝试重定向到我的 show 视图时。但是当我重定向到其他工作正常时。有什么意见吗?
缺少 [Route: account.show] [URI: show/{id}] 的必需参数。
我有 3 个刀片模板。 搜索、编辑和显示。
search.blade.php - 显示所有记录。
@foreach ($result as $row)
<tr class = "success">
<td>{{ $row->id }}</td>
<td>{{ $row->first_name }}</td>
<td>{{ $row->last_name }}</td>
<td>{{ $row->middle_name }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->username }}</td>
<td>
<a href = "{{ route ('account.show', $row->id) }}"><button type = "submit" class = "btn btn-info">View</button></a>
<a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a>
<a href = "{{ route ('result.destroyEmployee', $row->id) }}"><button type = "submit" class = "btn btn-danger">Archive</button></a>
</td>
</tr>
@endforeach
edit.blade.php - 点击提交按钮后出现错误的地方是Save
<div class = "col-md-6">
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit', $result->id) }}">
<h3>Edit Employee</h3>
<hr>
<div class = "form-group">
<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}">
</div>
<div class = "form-group">
<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}">
</div>
<div class = "form-group">
<button type = "submit" class = "btn btn-success">Save</button>
</div>
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
</form>
show.blade.php - 文本字段只会放置记录的值。
<div class = "col-md-6">
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.show', $result->id) }}">
<h3>View Employee</h3>
<hr>
<div class = "form-group">
<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" placeholder = "{{ $result->email }}" readonly>
</div>
<div class = "form-group">
<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" placeholder = "{{ $result->username }}" readonly>
</div>
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
</form>
路线:
//READ
Route::get('/search',
[
'uses' => '\App\Http\Controllers\AccountController@getEmployee',
'as' => 'account.search',
]);
//SHOW
Route::get('/show/{id}',
[
'uses' => 'AccountController@showEmployee',
'as' => 'account.show',
]);
//EDIT
Route::get('/edit/{id}',
[
'uses' => '\App\Http\Controllers\AccountController@editEmployee',
'as' => 'account.edit',
]);
//UPDATE
Route::post('/edit/{id}',
[
'uses' => '\App\Http\Controllers\AccountController@updateEmployee',
'as' => 'account.edit',
]);
【问题讨论】:
-
"{{ route ('account.show', ['result' => $result->id]) }}"应该可以解决问题。当routes接受参数时,route()助手将接受参数作为作为第二个参数传递的数组。如果您不想,则无需进行'key' => 'value'映射。 -
如果我通过
'result'作为我的route()中的键有什么区别?我试图运行你的 sn-p 但是当我点击提交按钮时说MethodNotAllowedHttpException
标签: php laravel laravel-5.2