Laravel method delete Ajax Request

Posted 2 months ago by palla451


                        <table id="table_id" class="table table-striped table-bordered">
                                <th>Room Id</th>
                                @foreach($bookings as $booking)
                                    <tr id="{{$booking->id}}">
                                        <td class="roomId">{{$booking->room_id}}</td>
                                        <td class="roomName">{{$booking->name}}</td>
                                        <td class="roomLocation">{{$booking->sede}}</td>
                                        <td class="start">{{$booking->start_date}}</td>
                                        <td class="end">{{$booking->end_date}}</td>
                                            <button type="submit" class="deleteProduct" data-id="{{ $booking->id }}" data-token="{{ csrf_token() }}">Delete</button>


    var id = $(this).data('id');
    var token = $(this).data('token');
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                url: '/dashboard/booking/deletebooking/'+id,
                type: 'delete', // replaced from put
                dataType: "JSON",
                data: {
                    "id": id // method and token not needed in data
                success: function (response)
                    console.log(response); // see the reponse sent
                error: function(xhr) {
                    console.log(xhr.responseText); // this line will save you tons of hours while debugging
                    // do something here because of error


Route::delete('dashboard/booking/deletebooking/{id}','[email protected]')->name('works.deletebooking');


public function deletebooking($id){

    $booking = Booking::where('id','=',$id)->get();

    return response()->json(['success' => true],200);


I have the error: message Method Illuminate\Database\Eloquent\Collection::delete does not exist. exception BadMethodCallException file /home/vagrant/code/pickbooking/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php line 100

Where am I wrong, please

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.