我不知道這個錯誤來自它說的地方。當我嘗試更新我的記錄時出現此錯誤。它正常工作,並更新到我的數據庫,但得到這個錯誤。它說,這在我的參數中漏掉了一些東西。我認爲我的錯誤是return redirect()->route('account.show');
當我試圖重定向到我的顯示視圖更新後。但是當我重定向到其他工作正常。有什麼意見?UrlGenerationException([路由]缺少必需的參數)
缺少[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 - 文本字段的只會地方 - 在這裏,我打提交按鈕,這是保存
<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\[email protected]',
'as' => 'account.search',
]);
//SHOW
Route::get('/show/{id}',
[
'uses' => '[email protected]',
'as' => 'account.show',
]);
//EDIT
Route::get('/edit/{id}',
[
'uses' => '\App\Http\Controllers\[email protected]',
'as' => 'account.edit',
]);
//UPDATE
Route::post('/edit/{id}',
[
'uses' => '\App\Http\Controllers\[email protected]',
'as' => 'account.edit',
]);
'「{{路線(」帳戶。 show',['result'=> $ result-> id])}}「'應該這樣做。當'routes'接受參數時,'route()'helper將接受參數作爲第二個參數傳遞的數組。如果你不想要,你不需要做'key'=>'value'映射。 – Ohgodwhy
如果我在我的'route()'中傳遞'result'作爲鍵,有什麼區別?我試圖運行你的代碼片段,但是當我點擊提交按鈕說'MethodNotAllowedHttpException' – Francisunoxx