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?
Try this