I’m working on a Laravel project and using route model binding to automatically inject model instances into my routes. However, I’m encountering an issue where some routes return a 404 error even though the model
instance exists in the database.
I have defined a route in my web.php file like this:
Route::get('/posts/archived/{post}', [PostController::class, 'show']);
PostController
namespace AppHttpControllers;
use AppModelsPost;
use IlluminateHttpRequest;
class PostController extends Controller
{
public function show(Post $post)
{
return view('posts.show', compact('post'));
}
}
Despite having records in the posts table, when I navigate to /posts/1 or any other valid ID, I get a 404 error. I’ve verified that the records exist in the database
Pwned is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.