Reputation: 1
I'm trying to create a restful api with Laravel 4 but all the time I get an error:
"Symfony\Component\HttpKernel\Exception\NotFoundHttpException","message":"Controller method not found."
I follow the explanation on routes-first-in-first-out. But I had no luck.
My routes looks like:
Route::group(array('prefix' => 'api/v1'), function(){
Route::resource('contact', 'ContactController');
});
Route::get('/', function(){
return View::make('hello');
});
And the method in the controller looks like
public function store()
{
// ... somecode
}
And I have no idea what I'm doing wrong. I already search here but I keep having the same result.
Does anyone know where is the problem?
Upvotes: 0
Views: 1483
Reputation: 2021
You need to learn more about Restful Controllers first. If you look closely on the docs page, on the table there..
your action store
says:
Verb Path Action Route Name
POST /resource store resource.store
which means:
verb
on the table above). path
is /resource, in your case api/v1/contact
Back to your question..
Going via the browser with a URL of 'api/v1/contact/store' will produce a GET request to that route, but store expects a POST request. if you submit a POST from a form to the store URL, it will succeed but going to it via browser(GET) will surely produce an error saying the route cannot be found since you don't have a get 'api/v1/contact/store' route declared..
Upvotes: 1
Reputation: 1
I found that after the post request that i made originally with javascript, that a redirect is triggerso taht it fails. I don't know why. The .htacces file is the original from laravel intalation and the virtual host is :
<VirtualHost *:80>
ServerName raulcm.laravel
DocumentRoot /var/www/raulcm.laravel/public
<Directory /var/www/raulcm.laravel/public>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Order deny,allow
Allow from all
</Directory>
ErrorLog /var/www/raulcm.laravel/logs/error.log
CustomLog /var/www/raulcm.laravel/logs/access.log common
</VirtualHost>
Upvotes: 0