I'm approaching Laravel 7 recently, I was wondering how to make the script more navigable and safe. In particular, I need to redirect the visitor in a basic page in case he enters a post with a missing or incorrect slug.
**localhost/post/my-test-slug** = ok
**localhost/post/** = missing slug, redirect to index
etc, I have already tried the isset / empty controller but I don't understand why it doesn't work. How can I solve it?
public function show($slug)
{
$post = DB::table('post')->where('slug', $slug)->first();
return view('show', ['post' => $post]);
}