私の見解は、このようなものです:解決方法laravel 5.3のApp Http Controllers UserController :: destroy()の引数2が欠落していますか?
@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
マイルート\ web.phpは、このようなものです:
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]));
}
のようなエラーが存在するがあります:
Route::get('users/destroy/{year}', '[email protected]')->name('users.destroy.year');
Route::resource('users', 'UserController');
私のコントローラは、このようなものですこれは:
ErrorException in UserController.php line 205: Missing argument 2 for App\Http\Controllers\UserController::destroy()
とURLは次のようになります。クリックボタンを削除するとhttp://localhost/mysystem/public/users/10
、私は、URLは次のようになりたい:http://localhost/mysystem/public/users/index/2020
は私を助けることができるすべての人はありますか?
あなたは ' 'ルート' => [ 'users.destroy'、$ USER-> ID]で同様年を提供する必要があります'、あなたがしています現在1つの議論が欠けている。 –
@Joel Hinz、私はこのように変わります: '{!! Form :: open(['route' => ['users.destroy'、$ user-> id、$ year]、 'method' => 'delete'])!} '。ボタンの削除をクリックすると、URLは 'http:// localhost/mysystem/public/users/10?2020'のようになります。だから、それは動作していません –
あなたはまた、ルートの定義からユーザーIDが不足しているように見えます。 –