UrlGenerationException(缺少[Route]的必需参数) [英] UrlGenerationException (Missing required parameters for [Route])

查看:86
本文介绍了UrlGenerationException(缺少[Route]的必需参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道此错误来自何处.尝试更新记录时出现此错误.它可以正常工作并更新到我的数据库中,但出现此错误.它说那遗漏了我的参数.我认为更新后尝试重定向到显示视图时,我的错误是return redirect()->route('account.show');.但是当我重定向到其他工作正常.有什么意见吗?

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?

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

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

我有3个刀片模板. 搜索编辑显示.

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

search.blade.php-显示所有记录.

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

@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-在这里,点击保存

edit.blade.php - Here where I got the error after hitting the submit button which is 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-文本字段将仅放置记录的值.

show.blade.php - Textfield's will just place the value of the records.

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

推荐答案

尝试更改此内容:

<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">

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

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

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

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

使用laravel集体,您可以执行以下操作:

With laravel collective you can do something like this:

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

这篇关于UrlGenerationException(缺少[Route]的必需参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆