【问题标题】:Laravel Nested Route issueLaravel 嵌套路由问题
【发布时间】:2013-09-29 09:21:56
【问题描述】:

我在使用 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());
    }
}

我可能做错了什么?

【问题讨论】:

    标签: php laravel laravel-4 nested-routes


    【解决方案1】:

    MethodNotAllowedHttpException 表示您使用的 HTTP 方法不正确。您在只接受 GET 的路由上使用 POST。

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

    profile.bands.store
    

    您的 .create 路由只是显示一个创建记录表单,要发布它,您必须使用 store。

    看看你的路线名称和方法使用

    php artisan routes
    

    【讨论】:

    • 不知道php artisan routes。谢谢。
    猜你喜欢
    • 2011-03-18
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多