resources/views/emp-list.blade.php

<script>
    $(document).ready(function(){
        $(".delete").click(function(e){
            e.preventDefault();
            idd = this.id;
            $.ajax({
                type:"post",
                data:{"idd":idd, "_token":"{{csrf_token()}}",'_method': 'DELETE',},
                url:"{{URL::to('delete_emp')}}",
                success:function(res){
                    location.reload();
                }
            });
        });
    });
</script>

<table class="table">
    <thead>
        <tr>
            <th>Name</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        @foreach($result as $row)
        <tr>
            <td>{{ $row->fname }}</td>
            <td>
                <a href="javascript:void(0)" id="{{ $row->id }}" class="btn btn-danger delete" onclick="return confirm('are you sure')">Delete</a>
            </td>
        </tr>
        @endforeach
    </tbody>
</table>

api/http/controller/UserController.php

public function delete_emp(Request $request)
{
    $id = $request->input('idd');
    DB::delete('delete from emp where id = ?',[$id]);
}

routes/web.php

Route::get('delete_emp','[email protected]_emp');

I am new in laravel 5 Now what am I doing here I want to delete a particular record on click delete button but currently what happens when I click on delete button there is an error I have got in my console. So, How can I solve this problem? Please help me.

Thank You

0 Answers