更新路由生成不正确的网址 [英] Update route generates incorrect url

查看:115
本文介绍了更新路由生成不正确的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的html刀片代码

{{ Form::open(array('route' => 'restaurants.update', 'class' => 'mainInformationContrainer')) }}

<ul>
    <li>
        <label>Website</label>
        <div class="oneInfo">
            <input type="text" value="{{$restaurant->website}}" />
        </div>
    </li>
    <li>
        <input type="submit" value="Save Changes"/>
        <input type="button" value="Cancle" class="cancelButton"/>
    </li>
</ul>

{{ Form::close() }}

但是表单的网址是:public/restaurants/%7Brestaurants%7D

以为我已经有了路线:

Route::resource('restaurants', 'RestaurantsController');

解决方案

@Mark Ba​​ker说%7B和%7D分别是{和},laravel希望您传递要更新的资源的ID.

如果看到带有操作的面板,您将注意到您必须通过资源ID.

PUT/PATCH   /resource/{resource}    update  resource.update

您可以使用route辅助功能对其进行修复.

{{ Form::open(array('route' => route('restaurants.update', $restaurant->id), 'class' => 'mainInformationContrainer')) }}

This is my html blade code

{{ Form::open(array('route' => 'restaurants.update', 'class' => 'mainInformationContrainer')) }}

<ul>
    <li>
        <label>Website</label>
        <div class="oneInfo">
            <input type="text" value="{{$restaurant->website}}" />
        </div>
    </li>
    <li>
        <input type="submit" value="Save Changes"/>
        <input type="button" value="Cancle" class="cancelButton"/>
    </li>
</ul>

{{ Form::close() }}

But the url for the form is : public/restaurants/%7Brestaurants%7D

Thought I already have the route:

Route::resource('restaurants', 'RestaurantsController');

解决方案

As @Mark Baker said %7B and %7D are { and } respectively , laravel expect you to pass the id of the resource you want to update.

If you see the board with the action you will notice that you have to pass the resource id.

PUT/PATCH   /resource/{resource}    update  resource.update

You can use the route helper function to fix it.

{{ Form::open(array('route' => route('restaurants.update', $restaurant->id), 'class' => 'mainInformationContrainer')) }}

这篇关于更新路由生成不正确的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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