0
votes

I have an update function in the controller that keeps getting back the error:

Too few arguments to function App\Http\Controllers\Controller::update(), 2 passed in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54 and exactly 3 expected

/**
     * @param Request $request
     * @param int $id
     * @param string $emailAddress
     * @return  Application|Factory|RedirectResponse|Redirector|View
     */
    public function update(Request $request, string $emailAddress, int $id)
    {

         $x =Model::find($emailAddress, $id); 
}

I'm not sure why I keep getting this error. Any ideas of what causes it?

my route to the update :

Route::post('/update', 'Controller@update')->name('controller.update');
1

1 Answers

0
votes

The way you've defined your update method indicates it is expecting two required parameters in the URL: emailAddress and id. This would usually be associated with a route defined as such:

Route::post('/update/{emailAddress}/{id}', 'YourController@update');

Laravel would normally know to put these two together, but since your route doesn't have any parameters, Laravel doesn't know where to get that information automatically. So, it doesn't pass in $emailAddress or $id, resulting in a native PHP error (that error is not Laravel-specific).

If you intend for these parameters to be in the URL, you should change your route.

If you intend for these parameters to come from the request (POST) data, then you only need the Request $request method parameter, and the rest can come from the Request object itself:

public function update(Request $request)
{
    $x = Model::find($request->input('emailAddress'), $request->input('id'));
}