سلام . من میخوام وقتی حذف کنم از sweet alert بیغام بله یا خیرو ببینم . چجوری میشه ؟ ممنونم
سلام
@rohi1386
از flash message ها میتونید استفاده کنید
تو داکیومنت لاراول هست
خیلی ساده با این لینک خودمم از لینک استفاده کردم
https://stackoverflow.com/questions/46034634/sweet-alert-confirmation-before-delete
شاید پاسخ شما همینجا باشد
function archiveFunction() {
event.preventDefault(); // prevent form submit
var form = event.target.form; // storing the form
swal({
title: "Are you sure?",
text: "But you will still be able to retrieve this file.",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, archive it!",
cancelButtonText: "No, cancel please!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
form.submit(); // submitting the form when user press yes
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
}
</script>```
این کدو میزنم ولی اصلا swal اجرا نمیشه اول که \یغام بدهاگر منظورتون اینکه که موقع حذف 1 گزینه بله یا خیر رو از کاربر بپرسید می تونید خیلی راحت با JavaScript این کارو بکنید. به شکل زیر :
function deletee(id) {
if(confirm('از حذف کاربر مطمئن هستید؟')){
$('#'+id).submit();
}
}
با تعریف تابع در JavaScript و call کردن اون برای دکمه حذف یعنی onClick تعریف کنید براش.
سلام کدتون مربوط به ورژن قدیمی هست از این کد استفاده کنید
function archiveFunction(event) {
event.preventDefault(); // prevent form submit
var form = event.target.form; // storing the form
swal({
title: "Are you sure?",
text: "But you will still be able to retrieve this file.",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
form.submit();
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
}سلام.
من برای حذف یک مقاله مینویسم شما با توجه به پروژتون تغییرش بدین.
ابتدا در فایل اصلی (منظورم همون فایلی که در تمام صفحات پنل کاربری مشترک هست در واقع فایلی که header و footer خودتون رو قرار دادین، کد زیر رو در قسمت footer قرار بدین) کد زیر رو بنویسید.
@if(\Illuminate\Support\Facades\Session::has('status'))
<script>
Swal.fire({ title: "{{ session('status') }}", confirmButtonText: 'تایید', icon: 'success'})
</script>
@endif
کدهای زیر رو در بلید مربوطه قرار بدین.
<a href="https://roocket.ir/{{ route('articles.destroy', $article->id) }}" onclick="destroyArticle(event, {{ $article->id }})"><i class="nav-icon fa fa-trash" style="color: white"></i></a>
<form action="{{ route('articles.destroy', $article->id) }}" method="POST" id="destroy-article-{{ $article->id }}">
@csrf
@method('delete')
</form>
<script>
function destroyArticle(event, id) {
event.preventDefault();
Swal.fire({
title: 'آیا مطمئن هستید این مقاله را میخواهید حذف کنید؟',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: 'rgb(221, 51, 51)',
cancelButtonColor: 'rgb(48, 133, 214)',
confirmButtonText: 'بله',
cancelButtonText: 'خیر'
}).then((result) => {
if (result.isConfirmed) {
document.getElementById(`destroy-article-${id}`).submit()
}
})
}
</script>
در کنترلر مربوط به حذف به صورت زیر عمل کنید.
public function destroy(Article $article)
{
$article->delete();
session()->flash('status', 'مقاله با موفقیت حذف شد');
return back();
}
موفق باشید.