简体   繁体   中英

Laravel 8: Missing required parameter

I want to send some data to a web route like this:

<form action="{{ route('questions.answers', $show->id, $show->user->name) }}" method="POST">

And then on web.php , I added this:

Route::post('questions/{question}{asker}/answer', [QuestionController::class, 'postAnswer'])->name('questions.answers');

But now it says:

Missing required parameter for [Route: questions.answers]

So what is going wrong here? How can I pass $show->id and $show->user->name to questions.answers route?

I would really appreciate any idea or suggestion from you guys...

Thanks in advance.

If you want to pass answer as parameter, you can use the below code:

Your Blade File

<form method="post" action="{{ route('questions.answers', ['question' => '', 'asker' => '', 'answer' => '']) }}" enctype="multipart/form-data">
    @csrf
    //---Your Data
</form>

web.php

Route::post('questions/{question}/{asker}/{answer}' , [QuestionController::class, 'postAnswer'])->name('questions.answers');

And if you want to send the answer in your form use this code:

Your Blade File

<form method="post" action="{{ route('questions.answers', ['question' => '', 'asker' => '']) }}" enctype="multipart/form-data">
    @csrf
    //---Your Answer Here
</form>

web.php

Route::post('questions/{question}/{asker}' , [QuestionController::class, 'postAnswer'])->name('questions.answers');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM