public function handle(UploadImage $command)
    {
        // check if the user can upload images, otherwise return
        $this->assertCan(
            $command->actor,
            'flagrow.image.upload'
        );

        $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'image');
        $command->file->moveTo($tmpFile);

        $file = new UploadedFile(
            $tmpFile,
            $command->file->getClientFilename(),
            $command->file->getClientMediaType(),
            $command->file->getSize(),
            $command->file->getError(),
            true
        );

        // validate the file
        $this->validator->maxFileSize = $this->settings->get('flagrow.image-upload.maxFileSize', 2048);
        $this->validator->assertValid(['image' => $file]);

        // resize if enabled
        if ($this->settings->get('flagrow.image-upload.mustResize')) {
            $manager = new ImageManager;
            $manager->make($tmpFile)->fit(
                $this->settings->get('flagrow.image-upload.resizeMaxWidth', 100),
                $this->settings->get('flagrow.image-upload.resizeMaxHeight', 100)
            )->save();
        }

        $image = (new Image())->forceFill([
            'user_id'       => $command->actor->id,
            'upload_method' => $this->settings->get('flagrow.image-upload.uploadMethod', 'local'),
            'created_at'    => Carbon::now(),
            'file_name'     => sprintf(
                '%d-%s.%s',
                $command->actor->id,
                Str::quickRandom(),
                $file->guessExtension() ?: 'jpg'
            ),
            'file_size'     => $file->getSize()
        ]);

        // fire the Event ImageWillBeSaved, which can be extended and/or modified elsewhere
        $this->events->fire(
            new ImageWillBeSaved($command->actor, $image, $file)
        );

        $tmpFilesystem = new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME)));

        $meta = $this->upload->uploadContents(
            $image->file_name,
            $tmpFilesystem->readAndDelete(pathinfo($tmpFile, PATHINFO_BASENAME))
        );

        if ($meta) {
            $image->file_url = array_get($meta, 'url');

            if ($image->isDirty()) {
                $image->save();
            }

            return $image;
        }

        return false;
    }
public function handle(UploadImage $command)
    {
        // check if the user can upload images, otherwise return
        $this->assertCan(
            $command->actor,
            'flagrow.image.upload'
        );

        $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'image');
        $command->file->moveTo($tmpFile);

        $file = new UploadedFile(
            $tmpFile,
            $command->file->getClientFilename(),
            $command->file->getClientMediaType(),
            $command->file->getSize(),
            $command->file->getError(),
            true
        );

        // validate the file
        $this->validator->maxFileSize = $this->settings->get('flagrow.image-upload.maxFileSize', 2048);
        $this->validator->assertValid(['image' => $file]);

        // resize if enabled
        if ($this->settings->get('flagrow.image-upload.mustResize')) {
            $manager = new ImageManager;
            $manager->make($tmpFile)->fit(
                $this->settings->get('flagrow.image-upload.resizeMaxWidth', 100),
                $this->settings->get('flagrow.image-upload.resizeMaxHeight', 100)
            )->save();
        }

        $image = (new Image())->forceFill([
            'user_id'       => $command->actor->id,
            'upload_method' => $this->settings->get('flagrow.image-upload.uploadMethod', 'local'),
            'created_at'    => Carbon::now(),
            'file_name'     => sprintf(
                '%d-%s.%s',
                $command->actor->id,
                Str::quickRandom(),
                $file->guessExtension() ?: 'jpg'
            ),
            'file_size'     => $file->getSize()
        ]);

        // fire the Event ImageWillBeSaved, which can be extended and/or modified elsewhere
        $this->events->fire(
            new ImageWillBeSaved($command->actor, $image, $file)
        );

        $tmpFilesystem = new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME)));

        $meta = $this->upload->uploadContents(
            $image->file_name,
            $tmpFilesystem->readAndDelete(pathinfo($tmpFile, PATHINFO_BASENAME))
        );

        if ($meta) {
            $image->file_url = array_get($meta, 'url');

            if ($image->isDirty()) {
                $image->save();
            }

            return $image;
        }

        return false;
    }
public function handle ( UploadImage $ command ) { // check if the user can upload images, otherwise return $ this -> assertCan ( $ command -> actor , 'flagrow.image.upload' ) ; $ tmpFile = tempnam ( $ this -> app -> storagePath ( ) . '/tmp' , 'image' ) ; $ command -> file -> moveTo ( $ tmpFile ) ; $ file = new UploadedFile ( $ tmpFile , $ command -> file -> getClientFilename ( ) , $ command -> file -> getClientMediaType ( ) , $ command -> file -> getSize ( ) , $ command -> file -> getError ( ) , true ) ; // validate the file $ this -> validator -> maxFileSize = $ this -> settings -> get ( 'flagrow.image-upload.maxFileSize' , 2048 ) ; $ this -> validator -> assertValid ( [ 'image' => $ file ] ) ; // resize if enabled if ( $ this -> settings -> get ( 'flagrow.image-upload.mustResize' ) ) { $ manager = new ImageManager ; $ manager -> make ( $ tmpFile ) -> fit ( $ this -> settings -> get ( 'flagrow.image-upload.resizeMaxWidth' , 100 ) , $ this -> settings -> get ( 'flagrow.image-upload.resizeMaxHeight' , 100 ) ) -> save ( ) ; } $ image = ( new Image ( ) ) -> forceFill ( [ 'user_id' => $ command -> actor -> id , 'upload_method' => $ this -> settings -> get ( 'flagrow.image-upload.uploadMethod' , 'local' ) , 'created_at' => Carbon :: now ( ) , 'file_name' => sprintf ( '%d-%s.%s' , $ command -> actor -> id , Str :: quickRandom ( ) , $ file -> guessExtension ( ) ? : 'jpg' ) , 'file_size' => $ file -> getSize ( ) ] ) ; // fire the Event ImageWillBeSaved, which can be extended and/or modified elsewhere $ this -> events -> fire ( new ImageWillBeSaved ( $ command -> actor , $ image , $ file ) ) ; $ tmpFilesystem = new Filesystem ( new Local ( pathinfo ( $ tmpFile , PATHINFO_DIRNAME ) ) ) ; $ meta = $ this -> upload -> uploadContents ( $ image -> file_name , $ tmpFilesystem -> readAndDelete ( pathinfo ( $ tmpFile , PATHINFO_BASENAME ) ) ) ; if ( $ meta ) { $ image -> file_url = array_get ( $ meta , 'url' ) ; if ( $ image -> isDirty ( ) ) { $ image -> save ( ) ; } return $ image ; } return false ; }
Handles the command execution.

@param UploadImage $command
@return null|string

@todo check permission
Handles the command execution .