Support the ongoing development of Laravel.io →
Requests Input Forms

My view is like this :

@foreach($users as $user)
    <tr>
        <td>{!! $user->id !!}</td>
        <td>{!! $user->username !!}</td>
        <td>{!! $user->phone !!}</td>
        <td>{!! $user->address !!}</td>
        <td>
            {!! Form::open(['route' => ['users.destroy', $user->id], 'method' => 'delete']) !!}
            <div class='btn-group'>
                <a href="{!! route('users.edit', [$user->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
                {!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
            </div>
            {!! Form::close() !!}
        </td>
    </tr>
@endforeach

My routes\web.php is like this :

Route::get('users/destroy/{year}', 'UserController@destroy')->name('users.destroy.year');

Route::resource('users', 'UserController');

My controller is like this :

public function destroy($id, $year)
{
    $user = $this->userRepository->findWithoutFail($id);

    if (empty($user)) {
        Flash::error('User not found');

        return redirect(route('users.index'));
    }

    $this->userRepository->delete($id);

    Flash::success('User deleted successfully.');

    // return redirect(route('users.index'));
    return redirect(route('users.index.year', ['year' => $year]));
}

There is exist error like this :

ErrorException in UserController.php line 205: Missing argument 2 for App\Http\Controllers\UserController::destroy()

And the url looks like this : http://localhost/mysystem/public/users/10

When click button delete, I want the url looks like this : http://localhost/mysystem/public/users/index/2020

Is there any people who can help me?

Last updated 3 years ago.
0

you are just send one argument, but on the controller you ara tring to get to arguments

0

@davicfg, I change like this : {!! Form::open(['route' => ['users.destroy', $user->id, $year], 'method' => 'delete']) !!}. When I click button delete, the url looks like this : http://localhost/mysystem/public/users/2?2026. So, it's not working

0

Sign in to participate in this thread!

Eventy

Your banner here too?

moschel26 moschel26 Joined 21 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.