Kris99's avatar

Event Listener not load

Hi! I want create a thumbnail from uploaded images with Orchid (https://orchid.software/) Follow they instructions https://orchid.software/en/docs/attachments/ but my UploadListener probably do not load. I am trying to create a log file, but it is not created. I just would like to get a copy of uploaded image like generated_name_thumb.jpg

My EventServiceProvider


namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
//use Orchid\Platform\Events\UploadFileEvent;
use App\Listeners\UploadListener;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array<class-string, array<int, class-string>>
     */
    protected $listen = [
		UploadFileEvent::class => [
             UploadListener::class,
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        //
		        parent::boot();

    }
}

My UploadListener


namespace App\Listeners;

use Orchid\Platform\Events\UploadFileEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
//use Image;
use Illuminate\Support\Facades\Log;

class UploadListener extends ShouldQueue
{
    use InteractsWithQueue;

    /**
     * Handle the event.
     *
     * @param  \App\Events\UploadFileEvent  $event
     * @return void
     */
    public function handle(UploadFileEvent $event)
    {
				//$image = Image::make($event->attachment);	
				//$image->makeThumbnail('image'); //This handles uploading image and storing it's thumbnail
			Log::info($event);
			
		/**/
     //   dd($event);
    }
}

UploadFileEvent from the Orchid package


declare(strict_types=1);

namespace Orchid\Platform\Events;

use Illuminate\Queue\SerializesModels;
use Orchid\Attachment\Models\Attachment;

/**
 * Class UploadFileEvent.
 */
class UploadFileEvent
{
    use SerializesModels;

    /**
     * @var Attachment
     */
    public $attachment;

    /**
     * @var int
     */
    public $time;

    /**
     * UploadFileEvent constructor.
     *
     * @param Attachment $attachment
     * @param int        $time
     */
    public function __construct(Attachment $attachment, int $time)
    {
        $this->attachment = $attachment;
        $this->time = $time;
    }
}
0 likes
2 replies
click's avatar

You defined ShouldQueue on the UploadListener which means that your event will be placed on the queue, if defined. Do you use the queue and if so, did you run it when you were testing it and did you also restart the queue when testing it? If not; please do both.

And otherwise you will have to start debugging, for example add something to the __construct() of the UploadListener to see if your event is working.

laracastsluvr's avatar

It might be silly what we can forget, but try

php artisan queue:work

// https://laravel.com/docs/9.x/queues#running-the-queue-worker

If it is already running, maybe try to restart the queue also?

Please or to participate in this conversation.