мой взгляд, как это:Как решить методNotAllowedHttpException в строке RouteCollection.php 218 :?
@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.year', $user->id, $year], '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 как это:
Route::get('users/destroy/{year}', '[email protected]')->name('users.destroy.year');
Route::resource('users', 'UserController');
Мой контроллер выглядит так:
public function destroy($id, $year)
{
$user = $this->userRepository->findWithoutFail($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index.year', ['year' => $year]));
}
$this->userRepository->delete($id);
Flash::success('User deleted successfully.');
return redirect(route('users.index.year', ['year' => $year]));
}
Существует существует ошибка, как это:
MethodNotAllowedHttpException in RouteCollection.php line 218:
И URL выглядит следующим образом: http://localhost/mysystem/public/users/2?2016
При нажатии кнопки удалить, я хочу, чтобы URL выглядит следующим образом: http://localhost/mysystem/public/users/index/2016
Есть ли люди, которые могут мне помочь?
Я использую http://labs.infyom.com/laravelgenerator/ или https://github.com/InfyOmLabs/adminlte-generator/tree/5.3. Кажется, что удаление было создано автоматически. Поэтому нет необходимости добавлять маршруты. –
Правильно. У вас уже есть этот ресурс Route :: ('users', 'UserController'); '; который добавит маршрут 'delete'. Я уточню свой ответ. – linuxartisan
При нажатии кнопки delete, я хочу, чтобы URL-адрес был здесь: http: // localhost/mysystem/public/users/index/2016. Как, если вы не объявили маршрут «GET»? –