UrlGenerationException(缺少[Route]所需的参数)

时间:2016-07-04 06:07:22

标签: php laravel laravel-5.2

我不知道这个错误来自哪里。我尝试更新记录时遇到此错误。它正常工作并更新到我的数据库,但收到此错误。它说在我的参数中遗漏了一些东西。当我在更新后尝试重定向到 show 视图时,我认为我的错误为return redirect()->route('account.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 - 点击提交按钮保存

后出现错误
<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 - Textfield将只放置记录的值。

<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',
]);

1 个答案:

答案 0 :(得分:2)

尝试改变这一点:

int main(void) {
  //                   size of element   how many 
  Date *dates = malloc(sizeof *dates   *   4);
  //Check for success
  if (dates) {
    // C11 use of compound literal  
    dates[0] = (Date){ 2016, 6, 12, "sunday"};  // a
    dates[1] = (Date){ 2016, 6, 13, "monday"};  // b
    dates[2] = (Date){ 2016, 4, 25, "monday"};  // y
    dates[3] = (Date){ 2016, 3, 27, "sunday"};  // z
    // do stuff with dates[]
  }
  // free when done, OK to free(NULL)
  free(dates)
  return 0;
}

要:

<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.show', $result->id) }}">

然后你必须将路由参数作为第二个参数传递给路由。这样的事情: <form class = "form-vertical" role = "form" action="{{ url('edit/'. $result->id) }}" method="POST">

*我建议您使用laravel集体表格:https://laravelcollective.com/

通过laravel集体你可以做这样的事情:

return redirect()->route('account.show', [$id])