I have a form that submits data to a database. And he sends the data to the database. But Laravel gives an error when it tries to redirect it to another method in the same controller.
ReflectionException in RouteDependencyResolverTrait.php line 57: Internal error: Failed to retrieve the default value

Here is the controller I am using. Check out the public function store(Request $request) method.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Inbox; class ContactUsController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('pages.contactus'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // validate the data // store the data in the database // redirect to another page $this->validate($request, [ 'name' => 'required|max:255', 'email' => 'required', 'telephone' => 'required', 'message' => 'required', ]); $inbox = new Inbox; $inbox->name = $request->name; $inbox->email = $request->email; $inbox->telephone = $request->telephone; $inbox->message = $request->message; $inbox->isnew = 1; $inbox->category = $request->category; $inbox->save(); // redirects to the route //return redirect()->route('contactus.show', $inbox->id); return redirect()->action( ' ContactUsController@show ', ['id' => 11] ); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { print_r($id); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }
And I tried to use both methods in two different cases. But Laravel every time shows the same error.
return redirect()->route('contactus.show', $inbox->id); return redirect()->action( ' ContactUsController@show ', ['id' => 11] );
And here is the web.php route web.php .
Route::get('contactus', ' ContactUsController@create '); Route::get('contactus/show', ' ContactUsController@show '); Route::post('contactus/store', ' ContactUsController@store ');
I donβt know what the problem is. Any suggestion would be helpful.
Thanks!
Isuru
source share