dillingham / nova-button

Add buttons on Nova index, detail and lens views.
MIT License
265 stars 33 forks source link

405 Method Not Allowed Http Exception #13

Closed Dontorpedo closed 5 years ago

Dontorpedo commented 5 years ago

click on the button returns

at first:

SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

than

405 Method Not Allowed Http Exception

i tried to use the NovaButton\Events\ButtonClick and also a custom event, but seems not to work.. what could be the problem?

dillingham commented 5 years ago

@dontorpedo can you show me the button code and the event listener for the custom event?

Dontorpedo commented 5 years ago

Buttoncode

            Button::make('Paid', 'paid')
                ->event('App\Events\UnpaidInvoices')
                ->successText('Done!')
                ->style('primary-outline')
                ->visible($this->invoice_paid == false),

listener

<?php

namespace App\Listeners;
use App\Events\UnpaidInvoices;

class MarkAsPaid
{
    public function handle(UnpaidInvoices $event)
    {

        $event->resource->paid_amount = $event->resource->netto_price * 1.2;
            $event->resource->invoice_paid = true;
        $event->resource->invoice_states = 2;
            $event->resource->save();

    }

}

and the custom event

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class UnpaidInvoices
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $key;
    public $resource;

    /**
     * Create a new event instance.
     *
     * @param  \App\Order  $order
     * @return void
     */
    public function __construct($resource, $key)
    {
        $this->resource = $resource;
        $this->key = $key;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}

tried also with the default event.. and also with and without keycheck..

dillingham commented 5 years ago

@Dontorpedo and you're on the latest version 1.0.3 ?

Thanks for the info, so far nothing seems wrong with your implementation.

Dontorpedo commented 5 years ago

@dillingham yes, its the newest version 1.0.3, i tried it also with 1.0.2

ppisecky commented 5 years ago

@Dontorpedo

Do you have your routes cached? Might be that you need to run php artisan route:clear

dillingham commented 5 years ago

I’ll re-open when more info is provided :)

vhkhb commented 5 years ago

I am getting the same error. I am also looking for the solution.

dillingham commented 5 years ago

@krunaldevs I don’t have enough info to reproduce this and am not experiencing it myself

vhkhb commented 5 years ago

My Resource File

Button::make('<i class="fa fa-copy copy text-70 hover:text-primary" title="Copy SMS Promotion"></i>')
->event(new DuplicatePromo($id))
->visible(true)
->onlyOnIndex(),

My Event Class

class DuplicatePromo
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $promo;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($promo_id)
    {
        $this->promo = SmsPromo::find($promo_id);
    }
}

My Listener File

class DuplicatePromoListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  DuplicatePromo  $event
     * @return void
     */
    public function handle(DuplicatePromo $event)
    {
        \Log::info('Duplicate Promotion', $event->promo);
    }
}

After clicking on button it will generate url like this

image

This is error getting from the Laravel

image

dillingham commented 5 years ago

@krunaldevs set an attribute to the button

make::(‘icon-html’, ‘some-attribute’)

dillingham commented 5 years ago

Also that’s not how you set events, check the readme.

vhkhb commented 5 years ago

@krunaldevs set an attribute to the button

make::(‘icon-html’, ‘some-attribute’)

I think this is the right way to use this Button

Button::make('<i class="fa fa-copy copy text-70 hover:text-primary" title="Copy SMS Promotion"></i>', 'duplicate_smspromo')
                ->event('App\Events\DuplicatePromo')
                ->visible(true)
                ->onlyOnIndex(),

This works for me Thanks @dillingham

Dontorpedo commented 5 years ago

it could have been a compability issue with another package, don't know the exact steps to reproduce but after updating laravel and nova to newest versions, and removing packages etc.. (i also did something with routes).. the nova button started working