문제

I'm having problem with the Laravel 4, nested routing. I can display the create method form but can't store. Here is the code, I'll just come to the point. I have a base Resource Controller and another nested controller

This is in my Routes.php

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

I don't think I have to display the profile's code here, I'll show you the BandsController

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

This will just display the form, as you know. The form is:

{{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()}}

Now, I didn't understand, the form action url looks good when I view it in browser but when I submit it I get, this error.

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());
    }
}

What might I have done wrong ?

도움이 되었습니까?

해결책

MethodNotAllowedHttpException means that the HTTP method you're using is not right. You're using POST on a route tha only accepts GET.

On your form, you must use the route

profile.bands.store

Your .create route is just to show a create record form, to post it you must use store.

Take a look at your routes names and methods using

php artisan routes
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top