微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Laravel嵌套路线问题

我对Laravel 4,嵌套路由有问题.我可以显示创建方法表单但无法存储.这是代码,我只是说到了这一点.
我有一个基本资源控制器和另一个嵌套控制器

This is in my Routes.PHP

Route::resource('profile','ProfileController');
Route::resource('profile.bands','BandsController');

我不认为我必须在这里显示配置文件代码,我将向您展示BandsController

public function create($profileId)
{
    return View::make('bands.create',['title' => 'Create Band Profile' , 'profileId' => $profileId]);
}

如您所知,这只会显示表单.
表格是:

{{Form::open( [ 'route' => ['profile.bands.create',$profileId]])}}
<input class="input" type="text" name="name" value="" />
<input class="input" type="text" name="city" value="" />
 <input type="submit" value="submit" />
    {{Form::close()}}

现在,我不明白,当我在浏览器中查看时,表单操作url看起来不错,但是当我提交它时,我得到了,这个错误.

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

open: E:\server\www\gigmor.com\gigmor\vendor\laravel\framework\src\Illuminate\Routing\Router.PHP
    // The method not allowed exception is essentially a HTTP 405 error, so we
    // will grab the allowed methods when converting into the HTTP Kernel's
    // version of the exact error. This gives us a good RESTful API site.
    elseif ($e instanceof MethodNotAllowedException)
    {
        $allowed = $e->getAllowedMethods();

        throw new MethodNotAllowedHttpException($allowed, $e->getMessage());
    }
}

我可能做错了什么?

解决方法:

MethodNotAllowedHttpException意味着您使用的HTTP方法不正确.你在一条只接受GET的路线上使用POST.

在您的表单上,您必须使用该路线

profile.bands.store

您的.create路线只是为了显示创建记录表单,发布它必须使用商店.

使用查看您的路线名称方法

PHP artisan routes

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐