I have a page which has numerous articles. I want to give the user the ability to 'like' an article and to store that like id into a database for reuse later. Im new to Laravel and Php, so here is what i have.
I have models for Article and the Like. and i have this in the public store ArticleController.
public function store()
{
$article = new Article();
$article->body = 'new article body';
$article->title = 'new article Title';
$article->type = 'fashion';
$article->save();
$request = Request::all();
$likes = new Like();
$likes->user_id = Auth::user()->id;
$likes->article_id = $article->id;
$likes->save();
return redirect('article');
}
I followed the tutorial on laravel fundamentals but i think i missed something. This is working for me here. But now i want to change it so that it only takes the existing article and does not make a new one. When i change it to reflect this:
$article = Article::find($id);
It tells me that the $id is not defined. So how do i make $id point to the article the user wants to 'like'?