I am building an application where users can like/unlike each others projects. I have build a system that allow users to like the work and every like gets stored in my database with a unique id, the project_id and the user_id.
Now I am building the Unlike part and get an error when hitting the Unlike button.
The error:
Sorry, the page you are looking for could not be found. NotFoundHttpException in RouteCollection.php line 161:
My routes:
Route::post('projects/{id}', 'LikesController@store');
Route::get('projects/{id}','LikesController@destroy');
My Controller
public function store(Request $request)
{
$input = Request::all();
$like = new Like;
$like->user_id = Auth::user()->id;
$like->project_id = $input['project_id'];
$like->save();
return redirect('projects/'.$input['project_id']);
}
public function destroy($id)
{
$input = Request::all();
Like::find($id)->delete();
return redirect('projects/'.$input['project_id']);
}
My form
@if (Auth::check())
@if ($isLikedUser)
{!! Form::open(array('url'=>'projects/'.$project->id.'/deletelike','method'=>'POST')) !!}
{!! Form::hidden('project_id', $project->id) !!}
{!! Form::Submit('Unlike', array('class'=>'send-btn')) !!}
{!! Form::close() !!}
@else
{!! Form::open(array('url'=>'projects/'.$project->id,'method'=>'POST', 'id'=>'likeform')) !!}
{!! Form::hidden('project_id', $project->id) !!}
{!! Form::Submit('Like', array('class'=>'send-btn')) !!}
{!! Form::close() !!}
@endif
@else
<p>Log in to like.</p>
@endif