Hello,
Your route has post method. Are you sure you are sending request with post method?
I am also getting the same error.
View:
@extends('layouts.main')
@section('content')
<h1>Create new account</h1>
{{ Form::open(['route' => 'account-create-post']) }}
...
<div>
{{ Form::label('password_confirm', 'Confirm password:') }}
{{ Form::password('password_confirm') }}
@if($errors->has('password_confirm')){{$errors->first('password_confirm')}}@endif
</div>
<div>{{ Form::submit('Create account') }}</div>
{{ Form::close() }}
@stop
AccountsController:
<?php
class AccountController extends BaseController {
public function getCreate(){
return View::make('account.create');
}
public function postCreate(){
return 'Hello.';
}
}
routes file:
/*
/Unauthenticated group
*/
Route::group(array('before' => 'guest'), function(){
/*
/ CSRF group
*/
Route::group(array('before' => 'csrf'), function(){
/*
/ Create account (POST)
*/
Route::get('/account/create', array(
'as' => 'account-create-post',
'uses' => 'AccountController@postCreate'
));
});
/*
/ Create account (GET)
*/
Route::get('/account/create', array(
'as' => 'account-create',
'uses' => 'AccountController@getCreate'
));
});
I think the problem is the POST but I don't know how to solve it.
Everything is explained here: http://laravel.com/docs/4.2/routing
If you want the route to be executed on POST method, you need to use Route::post()
instead of Route::get()
. But there's more, you can just make controllers' methods reflect URL directly, without adding routes. That's what Route::controller()
is for.
Just read it.
and how do i prevent a MethodNotAllowedHttpException in RouteCollection.php when someone access a post-route without giving post parameters?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community