$task = DB::table('tasks')->find($id);
return view('tasks.show', compact('tasks'));
See anything wrong there? $task and compact('tasks')? You're passing $task as $tasks to the view.
So change
return view('tasks.show', compact('task'));
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When browsing to blog.test/tasks/1, /tasks/2, or /tasks/3, I receive the following error from show.blade.php
ERROR: "Undefined variable: task (View: /resources/views/tasks/show.blade.php)"
Route::get('/tasks/{id}', function ($id) {
$task = DB::table('tasks')->find($id);
return view('tasks.show', compact('tasks')); });
If I browse to blog.test/tasks, the Unordered List displays correctly.
I have every file in the correct directory too, I believe. resources/views/welcome.blade.php resources/views/tasks/index.blade.php resources/views/tasks/show.blade.php
Why isn't show.blade.php unable to define $task?
$task = DB::table('tasks')->find($id);
return view('tasks.show', compact('tasks'));
See anything wrong there? $task and compact('tasks')? You're passing $task as $tasks to the view.
So change
return view('tasks.show', compact('task'));
Please or to participate in this conversation.