Laravel Middleware Too few arguments to function error

  laravel, php

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 AppHttpMiddlewareAdminUserUpdate::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' => AppHttpMiddlewareAdminUserUpdate::class,

Route:

Route::middleware(['AdminUserUpdate'])->group(function () {
        Route::post('/app/members/{id}/submit', '[email protected]')->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?

Source: Ask PHP

LEAVE A COMMENT