Home > database >  How do you redirect to a route passing in a additional parameter?
How do you redirect to a route passing in a additional parameter?

Time:10-30

controller:

public function edit(Request $request, Posts $posts) {
        $validatedRequests = $request->validate([
            'title' => 'required|max:255|string|integer',
            'description' => 'required|max:255|string|integer',
            'price' => 'required|integer|max:255|'
        ]);    

        $posts->update([
            'title' => $request->title,
            'description' => $request->description,
            'price' => $request->price    
        ]);    

        $posts->save();

        *return redirect(route('singelPost', ['post'=> $posts->id]))->with('mssg', 'updates successfully');* 
    }

web.php:

Route::get('/post/{post:id}', [PostController::class, 'show'])->name('singlePost');

That is the error i get: Missing required parameter for [Route: showEditForm] [URI: post/{post}/editForm] [Missing parameter: post].

CodePudding user response:

Could you have made a mistake code/syntax? Try this:

return redirect()->route('singlePost', $posts->id)->with('mssg', 'updates successfully');

CodePudding user response:

The issue is from your route in web.php where you have {post:id}

Change your route definition to this instead:

Route::get('/post/{post}', [PostController::class, 'show'])->name('singlePost');
  • Related