I have just followed a tutorial where the only code I needed in web.php to call a controller function was:
Route::resource('/articles', 'ArticleController');
This works for all my functions that were already there when creating the project (edit, update, destroy,...) Now I need to make a second update function (upvote). But when creating a new function in the controller and routing to it I get the following error:
Route [articles.upvote] not defined. (View: D:\school\web-backend\Oplossingen\hackernews\resources\views\articles\index.blade.php)
How do I make the "a" tag go to the upvote function of the controller? My code:
public function upvote(Request $request, $id)
{ /* ArticleController.php */
$article = Article::find($id);
$article->points += 1;
$article->save();
Session::flash('succes', 'Upvote was a succes');
return redirect()->route('articles.index');
}
td> <!-- index.blade.php !-->
<a href="{{ route('articles.upvote', ['articles'=>$storedArticle->id]) }}" class="btn btn-default">upvote</a>
</td>
<td>downvote</td>
<td>
<a href="{{ route('articles.edit', ['articles'=>$storedArticle->id]) }}" class="btn btn-default">edit</a>
</td>
Route::get('/', function () { /*route\web.php */
return view('welcome');
});
Route::resource('/articles', 'ArticleController');