I'm trying to update a column in my database with a total of votes on a project. I'm having a 404 problem but I don't see the problem in my route. (PS: Laravel 3)
This is my Vote button on every project :
{{ Form::open('project/addvote', 'VOTE') }}
{{ Form::hidden('id', $project->id) }}
{{ Form::submit('Vote') }}
{{ Form::close() }}
So when you click on the vote button it use this route :
Route::put('project/addvote', array('uses'=>'projects@addvote'));
And this is my action in the projects controller (no updating yet, just trying to redirect) :
public function put_addvote(){
return Redirect::to_route('project', $id)
->with('message', 'Vote successful');
}
Redirecting to this route :
Route::get('project/(:num)', array('as'=>'project', 'uses'=>'projects@project'));
And this is getting me the 404 error
Thanks to every response and the great help here!
Actually,Redirect::to_route
expects a name of a route to redirect to it and a named route has to be declare with a name, like,Route::put('project/addvote', array('as' => 'project', 'uses'=>'projects@addvote'));So, you can use it;s name to redirect to it likereturn Redirect::to_route('project');Here,project
has been used as it's name using'as' => 'project'
. In, your example, you didn't gave any name to the route, hereRoute::put('project/addvote', array('uses'=>'projects@addvote'));The,as => 'route_name'
is missing.For second question, you can do it as
Inserting & Updating Models.
Update :
It was a bit confusing but after a conversation through the commenting system the answer for routing is give below :
You (OP) mentioned that you have a route declared as
To this route you are trying to redirect using this
So, you are passing a parameter and it's not in your route declaration and this is the problem, so to overcome this change your route declaration to this
Or
Or, you can make the param optional using a
?
, for example :Check wildcard Routes.
Update :
You should have postd the original code with the question, anyways,Change thisto