Laravel-filemanager: Event not working

Created on 13 Jul 2018  路  9Comments  路  Source: UniSharp/laravel-filemanager

i tried using imagewasuploaded event to resize image but nothing is happening, i also tried to log the path, but nothing happened, pls wat am i getting wrong?
img_20180713_182325

Most helpful comment

@fixer112
Hi, I had the same problem,

Change the line : use Unisharp\Laravelfilemanager\Events\ImageWasUploaded;
to:
use UniSharp\LaravelFilemanager\Events\ImageWasUploaded;

Notice the capital 'S' in UniSharp and the capital 'F' in LaravelFilemanager

Hope this helps,
Vincent

All 9 comments

any help?

@fixer112 did you register your event listener in EventServiceProvider.php?

yes i did...

//EventServiceProvider.php
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Unisharp\Laravelfilemanager\Events\ImageWasUploaded;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\Event' => [
            'App\Listeners\EventListener',
        ],
        ImageWasUploaded::class => [
            'App\Listeners\UploadListener',
        ],
    ];

//UploadListener.php
<?php

namespace App\Listeners;

use UniSharp\LaravelFilemanager\Events\ImageWasUploaded;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Image;
class UploadListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  ImageWasUploaded  $event
     * @return void
     */
     public function handle(ImageWasUploaded $event)
     {
         /*$method = 'on'.class_basename($event);
         if (method_exists($this, $method)) {
             call_user_func([$this, $method], $event);
         }*/
         $path = $event->path();
         //your code, for example resizing and cropping
         $img = Image::make($path);
         $img->resize(500, 500);
         $img->save($path);
         Log::debug('image path '.$path);
     }

@fixer112
Hi, I had the same problem,

Change the line : use Unisharp\Laravelfilemanager\Events\ImageWasUploaded;
to:
use UniSharp\LaravelFilemanager\Events\ImageWasUploaded;

Notice the capital 'S' in UniSharp and the capital 'F' in LaravelFilemanager

Hope this helps,
Vincent

I had the same issue

@VincentVanWijk thanks alot

Thanks @VincentVanWijk for the fix!

Thanks @VincentVanWijk

Hello Sir @gwleuverink, I guess, we must re-open the issue. As of v2.0.0-alpha7 which I am currently using, the docs and the demo here are still not updated.

I can help by making a PR to update the docs but the problem that I am thinking is that is the namespace like that before especially for V1? Is it a recent change only for V2. Sorry because I just recently used this plugin.

Regards,

EDIT: Already created https://github.com/UniSharp/laravel-filemanager/pull/746

Was this page helpful?
0 / 5 - 0 ratings

Related issues

intergalactisch picture intergalactisch  路  5Comments

asimshazad picture asimshazad  路  4Comments

sanvu88 picture sanvu88  路  3Comments

rlrlaa123 picture rlrlaa123  路  3Comments

farshidrezaei picture farshidrezaei  路  4Comments