Since POST /contact-us
posts to the index route, create a postIndex
method:
public function postIndex($data) {
//Handle form
return View::make('contact-us-success');
}
Question
I've worked with MVC's using Java but first time using Laravel. In Java I can indicate in my controller the URL and method (POST or GET) to handle. I can't seem to figure out how to do this in Laravel for a contact us form that emails me when a user fills out the form.
In routes.php I have:
Route::controller('/contact-us', 'ContactUsController');
In my ContactUsController I have:
public function getIndex() {
return View::make('contact-us');
}
public function postForm($data) {
//Handle form
return View::make('contact-us-success');
}
With the "getIndex()" function I can see the contact us page. However clicking "Submit" on the form (which submits to the same /contact-us URL as the GET page) gives me a "Controller method not found" error. Do I need to make the form submit to something like contact-us/store or is it possible to have the GET/POST page be the same URL? Also, I want to use my controllers to handle routes instead of putting a new line in routes.php for everything.
Solution
Since POST /contact-us
posts to the index route, create a postIndex
method:
public function postIndex($data) {
//Handle form
return View::make('contact-us-success');
}