Only the post author will be able to delete their own post
public function destroy($id)
{
    $post = POST::find($id);

    // Check for correct user
    if (auth()->user()->id !== $post->user_id) {
        return redirect('/posts')->with('error', 'Unauthorized page');
    }

    $post->delete();
    return view('posts')->with('success', 'Post Removed');
}
by Valeri Tandilashvili
4 years ago
Laravel
auth
Laravel From Scratch
2
Pro tip: use ```triple backticks around text``` to write in code fences