Last active
June 25, 2019 02:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@if (!empty($user->name)) | |
{{ $user->name }} | |
@endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 省略 --> | |
<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> | |
<!-- 省略 --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@if (Session::has('message')) | |
<p>{{ session('message') }}</p> | |
@endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function destroy($id) | |
{ | |
$user = User::find($id); | |
// 処理やら | |
if ($user->delete()) { | |
return redirect('/top')->with('message', '削除しました。'); | |
} | |
return redirect('/top')->with('message', 'エラー'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::resource('users', 'UsersController'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment