私はLaravelのSweet Alertで削除モーダルを作成しました。これは私が選択したユーザーを削除しています。しかし、削除後に私のdestroy()
メソッドが言うように、ユーザーリストにリダイレクトするのが好きです。ここでSweet Alertリダイレクトを使用したLaravel
<script>
$('a#delete_user').on('click', function() {
var url = $(this).attr("data-href");
swal({
title: "Delete user?",
text: "Submit to delete",
type: "warning",
showCancelButton: true,
closeOnConfirm: false,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Delete!"
},
function() {
setTimeout(function() {
$.ajax({
type: "POST",
url: url,
data: {
_method: 'DELETE',
_token: csrf_token
},
success: function (data) {
if (data)
swal("Deleted!", "User has been deleted", "success");
else
swal("cancelled", "User has not been deleted", "error");
}
}), 2000
});
});
})
</script>
がコントローラである:
public function destroy($id)
{
User::destroy($id);
return redirect('users')->with('status', 'User Deleted!');
}
私は、メッセージをユーザーリストにリダイレクトしたい、と私はトラブルあなたのメインのテンプレートファイルでは、ビューファイルでそう
は、それがトリガーされません。そして、 'location.reload()'を設定した場合、ステータスは転送されません。 – Norgul
トリガされていないものをチェックする必要があります - 甘いアラートコールかセッション( 'status')が空です。 – sebbz
私の解決策はあなたがユーザー削除ボタンでajaxリクエストを削除する場合にのみ機能します。 ajax呼び出しを使用すると、コントローラのリダイレクト部分は機能しません。 – sebbz