Amaynut
Amaynut

Reputation: 4271

Laravel route not defined

I'm trying to send a contact form with Laravel So in the top of my contact form I have this

{{ Form::open(['action' => 'contact', 'name'=>"sentMessage", 'id'=>"contactForm"])}}

I have routes for contact page like this

Route::get('/contact', 'PagesController@contact');
Route::post('/contact','EmailController@test');

in my EmailController file I have something like this

public function test()
{
    return View::make('thanks-for-contact');
}

Whenever I open my contact page I get this error message

Route [contact] not defined

Upvotes: 0

Views: 2258

Answers (2)

teeyo
teeyo

Reputation: 3755

when you use the attribute action you provide it a method in your controller like so :

// an example from Laravel's manual
Form::open(array('action' => 'Controller@method'))

maybe a better solution with be to use named routes, which will save you a lot of time if you ever wanted to change your URL.

Route::get('/contact', array('as' => 'contact.index', 'uses' => 'PagesController@contact'));
Route::post('/contact', array('as' => 'contact.send', 'uses' => 'EmailController@test'));

then your form will look something like this :

{{ Form::open(array('route' => 'contact.send', 'name'=>"sentMessage", 'id'=>"contactForm")) }}

Upvotes: 3

user4278778
user4278778

Reputation:

You are using 'action' in your opening tags, so its trying to go to a controller by that name. Try using 'url' => 'contact'.

Upvotes: 0

Related Questions