Skip to content

Instantly share code, notes, and snippets.

@sola-msr
Last active June 25, 2019 02:09
Show Gist options
  • Save sola-msr/81a91a11a8cd805d1dfb1c87044fb857 to your computer and use it in GitHub Desktop.
Save sola-msr/81a91a11a8cd805d1dfb1c87044fb857 to your computer and use it in GitHub Desktop.
【Laravel】Laravelでよく使うroute()とview()とredirect()まとめ ref: https://qiita.com/sola-msr/items/4f92686d474118d1cceb
@if (!empty($user->name))
{{ $user->name }}
@endif
<!-- 省略 -->
<a href="{{ route('users.edit', ['id' => $user->id]) }}">編集する</a>
<form method="POST" action="{{ route('users.destroy', ['id' => $user->id]) }}">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" onclick="return window.confirm('削除しますか?');">
<span>削除する</span>
</button>
</form>
<!-- 省略 -->
@if (Session::has('message'))
<p>{{ session('message') }}</p>
@endif
public function destroy($id)
{
$user = User::find($id);
// 処理やら
if ($user->delete()) {
return redirect('/top')->with('message', '削除しました。');
}
return redirect('/top')->with('message', 'エラー');
}
Route::resource('users', 'UsersController');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment