Level 75
You already have a post
Route::get('/posts/{post:slug}', function (Post $post) {
return view('post', ['post' => $post]);
})->name('post');
Read the documentation one more time.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone!
I have a posts table which has the following structure:
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->foreignId('author_id');
$table->text('excerpt');
$table->text('content');
$table->timestamps();
});
which is currently migrated successfully. I'm trying to do the following in my `routes/web.php:
Route::get('/posts/{post:slug}', function (Post $post) {
return view('post', [
'post' => Post::firstOrFail($post)
]);
})->name('post');
but when I try to access 127.0.0.1:8000/posts/my-first-post I'm getting an error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.`000000Z","updated_at"?}` from `posts` limit 1' at line 1
What on earth?
You already have a post
Route::get('/posts/{post:slug}', function (Post $post) {
return view('post', ['post' => $post]);
})->name('post');
Read the documentation one more time.
Please or to participate in this conversation.