This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

d0pey
d0pey

I try to create a onDelete action. I have only a problem with the query My javascript and button


    $("#remove_book").click(function(){
        $(this).data('request-data', {
            book_checked: $('.list-checkbox input[type=\'checkbox\']').listWidget('getChecked')
        })
    });


 button
        class="btn btn-danger oc-icon-trash-o"
        disabled="disabled"
        id="remove_book"
        data-request="onDelete"
        data-request-confirm="Sure ?"
        data-trigger-action="enable"
        data-trigger=".control-list input[type=checkbox]"
        data-trigger-condition="checked"
        data-request-success="$el.prop('disabled', false)"
        data-stripe-load-indicator>
        Delete    

My onDelete function just have to delete the book what was selected. But I get the follow error: "Call to a member function delete() on a non-object" on line 43 of /www/testdomain/http/plugins/testplugin/book/controllers/Books.php

public function index_onDelete()
    {
        $postId = post('book_checked');
           Book::whereIn('id', $postId)
            ->delete();
            $post = book::find($postId);
                $post->delete();
        \Flash::success('Book Successfully deleted.');
        return $this->listRefresh();
    }

What means Call to a member function delete() on a non-object. The delete function is a default October function right?

Last updated

Wouter
Wouter

I don't see no why it don't work. I have look into a other plugin how they have create the ondelete function and I end up with this:

public function onDelete()
    {
        if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
            foreach ($checkedIds as $postId) {
                if ((!$post = book::find($postId)) ) 
                    continue;
                $post->delete();
            }
 Flash::success('Book deleted');
        }

button:

<button class="btn btn-default oc-icon-trash-o" disabled="disabled" onclick="$(this).data('request-data', { checked: $('.control-list').listWidget('getChecked') })" data-request="onDelete" data-request-confirm="Sure ?" data-trigger-action="enable" data-trigger=".control-list input[type=checkbox]" data-trigger-condition="checked" data-request-success="$el.prop('disabled', false)" data-stripe-load-indicator> Delete

If I understand it right with post('checked') you add the selected ids to the var.

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.