flugscoding
flugscoding

Reputation: 23

Laravel Too few arguments to function, 0 passed and exactly 1 expected

So I'm making a member promote function, I've set it up correctly but for some reason, I get the error: Laravel Too few arguments to function, 0 passed and exactly 1 expected

This is my route method:

Route::post('...

This is the form:

<form action="{{ route('members.promote', ['id' => $staff_member->id]) }}" method="POST">
    @csrf
        <button type="submit" class="btn-floating btn-large waves-effect waves-light btn-small green">
          <i class="material-icons">keyboard_arrow_up</i>
        </button>
</form>

Here's the controller:

public function promote($id)
    {
        $query = User::find($id);

        $query->auth = $query->auth + 1;
        $query->save();

        return redirect()->route('members.manage');
    }

I understand the error means that I haven't passed an ID in, but I clearly have. It also adds ?id=1 to my URL so I clearly have set it up correctly..

Thanks.

Upvotes: 1

Views: 587

Answers (2)

A.A Noman
A.A Noman

Reputation: 5270

Try this

Route::post('/your_url_name/{id}',[
    'uses'=>'ControllerName@promote',
    'as'=>'members.promote'
]);

Upvotes: 0

deviloper
deviloper

Reputation: 7240

You need to have a route defined in your route file with something like:

Route::post('members/promote/{id}', 'ControllerName@promote');

or if you are grouping your routes:

Route::group(array('prefix' => 'members'),function() {
    Route::post('promote/{id}', 'ControllerName@promote');
    ....//Other members routes
});

Upvotes: 1

Related Questions