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

时间:2021-06-20 10:58:56

I don't know where this error came from it says. I got this error when I tried to update my records. It works properly and updating into my database but getting this error. It says that that missed something in my parameter. I think my error is return redirect()->route('account.show'); when I tried to redirect to my show view after updating. But when I redirect to other works fine. Any opinions?

我不知道这个错误来自哪里。我尝试更新记录时遇到此错误。它正常工作并更新到我的数据库,但收到此错误。它说在我的参数中遗漏了一些东西。我认为我的错误是return redirect() - > route('account.show');当我在更新后尝试重定向到我的节目视图时。但是当我重定向到其他工作正常。任何意见?

Missing required parameters for [Route: account.show] [URI: show/{id}].

缺少[Route:account.show] [URI:show / {id}]所需的参数。

I have 3 blade template. search, edit and show.

我有3个刀片模板。搜索,编辑和显示。

search.blade.php - To show all the records.

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 - Here where I got the error after hitting the submit button which is Save

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's will just place the value of the records.

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>

Routes:

路线:

//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 个解决方案

#1


1  

Try to change this:

试着改变这个:

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

To:

至:

 <form class = "form-vertical" role = "form" action="{{ url('edit/'. $result->id) }}" method="POST">

Then you have to pass the route parameters as second argument to route. Something like this: return redirect()->route('account.show', [$id])

然后你必须将路由参数作为第二个参数传递给路由。像这样:return redirect() - > route('account.show',[$ id])

*I would recommend you to use laravel collective form: https://laravelcollective.com/

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

With laravel collective you can do something like this:

有了laravel集体,你可以这样做:

{!! Form::open(array('route' => array('account.show', $result->id))) !!}

#1


1  

Try to change this:

试着改变这个:

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

To:

至:

 <form class = "form-vertical" role = "form" action="{{ url('edit/'. $result->id) }}" method="POST">

Then you have to pass the route parameters as second argument to route. Something like this: return redirect()->route('account.show', [$id])

然后你必须将路由参数作为第二个参数传递给路由。像这样:return redirect() - > route('account.show',[$ id])

*I would recommend you to use laravel collective form: https://laravelcollective.com/

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

With laravel collective you can do something like this:

有了laravel集体,你可以这样做:

{!! Form::open(array('route' => array('account.show', $result->id))) !!}