mercredi 1 juin 2016

ModelNotFoundException when passing Model Object in Event constructor

This is my controller:

$transaction = new ProductTransactionLog();
Event::fire(new SendResponseToProduct($response, $transaction));

This is event class (SendResponseToProduct):

use Illuminate\Queue\SerializesModels;
use App\Models\ProductTransactionLog;

class SendResponseToProduct extends Event
{
    use SerializesModels;

    public $response = [];
    public $transaction;

    /**
     * Create a new event instance.
     */
    public function __construct($response = [], ProductTransactionLog $product_transaction)
    {
        // dd($transaction);
        $this->response = $response;
        $this->transaction = $product_transaction;
        // dd($this->transaction);
    }
}

This is in the EventServiceProvider:

protected $listen = [
        'App\Events\SendResponseToProduct' => [
            'App\Listeners\ResponseToProductListener',
        ],
    ];

When I run the controller, i.e when I fire the Event, I get this weird error:

NotFoundHttpException in Handler.php line 46: No query results for model [App\Models\ProductTransactionLog].

When I dd in the Event constructor, I get the object. When I uncomment dd, I get the error again.

When I dd in the Listener class, I get this same error. It does not reach the Listener class.

What is it that I am missing here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire