2 weeks ago

Delete Data

Posted 2 weeks ago by oxbir

I want to delete data using modal, I already get the id of the data I want to delete, but when I click the delete button in modal nothing happen.. Please tell me if something wrong.. Thank you very much.

blade and ajax


    <div class="col-md-10 p-5 pt-2">
        <h3><i class="fas fa-tachometer-alt ml-2"></i>دسته بندی ها</h3><hr>
        <a href="{{ route('categories.create') }}" class="btn btn-primary mb-3">
            <i class="fas fa-plus-square"></i>
            افزودن دسته بندی جدید
        <div class="table-responsive">
            <table class="table table-bordered table-striped">
                    <th>نام دسته</th>
                    <th>تاریخ ایجاد شده</th>
                    <th>اکشن ها</th>
                @foreach($categories as $category)
                        <td>{{ $category->id }}</td>
                        <td>{{ $category->name }}</td>
                        <td>{{ $category->created_at }}</td>
                            <div class="btn-group btn-group-sm">
                                <a href="{{ route('categories.edit', $category->id) }}"  class="btn btn-primary">ویرایش</a>
                                <button type="button" class="btn btn-danger" data-category="{{ $category->id }}" data-toggle="modal" data-target="#deleteCategory">حذف</button>

    <div class="modal fade" id="deleteCategory" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="deleteCategory" aria-hidden="true">
        <div class="modal-dialog modal-sm" role="document">
            <form action="{{ route('categories.destroy', $category->id) }}">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">این عمل برگشت پذیر نیست..</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                    <div class="modal-body">
                        آیا از حذف {{ $categories[0]->name }} اطمینان دارید؟
                        <input type="hidden" id="category" name="category_id">
                    <div class="modal-footer">
                        <button type="button" class="btn bg-white" data-dismiss="modal">بستن</button>
                        <button type="button" class="btn btn-danger">حذف</button>

        $('#delete').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var category = button.data('category');
            var modal = $(this);
            modal.find('.modal-body #categoey').val(category);


Route::resource('categories', 'CategoryController');


public function destroy(Category $category)
    return redirect()->route('categories.index');

Please sign in or create an account to participate in this conversation.