2021年4月8日星期四

Laravel Middleware Too few arguments to function error

I am trying to setup a middleware to check if inputs are empty on form submit for updating a users settings, and if so to return them back to the same page with an error. When I set it up, it gives me the error

Too few arguments to function App\Http\Middleware\AdminUserUpdate::handle(), 2 passed in /var/www/market/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php on line 167 and exactly 3 expected  

It seems to be the id I pass through, here is the rest of my code

Middleware:

  public function handle(Request $request, Closure $next, $id)      {          if($request->input('username') == NULL) {              return redirect()->route('admin.members.view', $id)->with('error', 'You must enter a username for this user in order to update their account!');          } elseif($request->input('email') == NULL) {              return redirect()->route('admin.members.view', $id)->with('error', 'You must enter a email for this user in order to update their account!');          } elseif($request->input('admin') == NULL) {              return redirect()->route('admin.members.view', $id)->with('error', 'You must select whether this user is a root admin or not in order to update their account!');          } elseif($request->input('banned') == NULL) {              return redirect()->route('admin.members.view', $id)->with('error', 'You must select whether this user is banned or not in order to update their account!');          } elseif($request->input('role') == NULL) {              return redirect()->route('admin.members.view', $id)->with('error', 'You must select a role for this user in order to update their account!');          }            return $next($request);      }  

Kernel:

'AdminUserUpdate' => \App\Http\Middleware\AdminUserUpdate::class,  

Route:

Route::middleware(['AdminUserUpdate'])->group(function () {          Route::post('/app/members/{id}/submit', 'App\Http\Controllers\Admin\Members\IndexController@Submit')->name('admin.members.submit');       });  

I have the ID passed through so I can return them back to the view page for the specific users id, but it doesnt seem to like that for some reason. Anyone have any thoughts?

https://stackoverflow.com/questions/67005545/laravel-middleware-too-few-arguments-to-function-error April 08, 2021 at 09:57PM

没有评论:

发表评论