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 like
return 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, here
Route::put('project/addvote', array('uses'=>'projects@addvote'));
The, as => 'route_name'
is missing.
For second question, you can do it as
$id = Input::get('id');
Project::find($id);
Project->votenumber = 5;
Project->->save();
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
Route::get('projets', array('as'=>'projets', 'uses'=>'projets@index'));
To this route you are trying to redirect using this
return Redirect::to_route('project', $id);
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
Route::get('projets/(:num)', array('as'=>'projets', 'uses'=>'projets@index'));
Or
Route::get('projets/(:any)', array('as'=>'projets', 'uses'=>'projets@index'));
Or, you can make the param optional using a ?
, for example :
Route::get('projets/(:any?)', array('as'=>'projets', 'uses'=>'projets@index'));
Update :
You should have postd the original code with the question, anyways, Change this
return Redirect::to_route('project', $id);
to
return Redirect::to_route('project', array($id));