src/ImageUploader.php
public function handle($framework_file, ImageConfiguration $config, array $optional_data = [])
    {
        /* Create ImageFile object for processing */
        $image_file = $this->prepareImageFile($framework_file);

        /* run validation on upload */
        $response = $this->validator->validate($image_file, $config->rules);

        /* if valid create database entry, store image to disk and generate response */
        if ($response->success()) {

            if ($record = $this->image_repo->findExistingImageable($config->optional_data)) {
                $this->image_repo->delete($record);
            }

            $record = $this->image_repo->create([
                'name'        => $config->image_name,
                'disk'        => $config->temp_disk,
                'filename'    => $image_file->filename,
                'path'        => $config->directory,
                'status'      => 'pending',
                'width'       => $image_file->width,
                'height'      => $image_file->height,
                'mime_type'   => $image_file->mime_type,
                'extension'   => $image_file->extension,
                'size'        => $image_file->size,
                'alt'         => $optional_data['alt'] ?? null,
                'title'       => $optional_data['title'] ?? null,
                'description' => $optional_data['description'] ?? null,
            ]);

            $this->storage->put($image_file->stream, $record->disk, "$record->path/$record->uuid", $record->filename);
            $response = new StandardServiceResponse(true, [
                'image' => $record,
            ], 'File successfully uploaded');
        }

        return $response;
    }
public function handle($framework_file, ImageConfiguration $config, array $optional_data = [])
    {
        /* Create ImageFile object for processing */
        $image_file = $this->prepareImageFile($framework_file);

        /* run validation on upload */
        $response = $this->validator->validate($image_file, $config->rules);

        /* if valid create database entry, store image to disk and generate response */
        if ($response->success()) {

            if ($record = $this->image_repo->findExistingImageable($config->optional_data)) {
                $this->image_repo->delete($record);
            }

            $record = $this->image_repo->create([
                'name'        => $config->image_name,
                'disk'        => $config->temp_disk,
                'filename'    => $image_file->filename,
                'path'        => $config->directory,
                'status'      => 'pending',
                'width'       => $image_file->width,
                'height'      => $image_file->height,
                'mime_type'   => $image_file->mime_type,
                'extension'   => $image_file->extension,
                'size'        => $image_file->size,
                'alt'         => $optional_data['alt'] ?? null,
                'title'       => $optional_data['title'] ?? null,
                'description' => $optional_data['description'] ?? null,
            ]);

            $this->storage->put($image_file->stream, $record->disk, "$record->path/$record->uuid", $record->filename);
            $response = new StandardServiceResponse(true, [
                'image' => $record,
            ], 'File successfully uploaded');
        }

        return $response;
    }
public function handle ( $ framework_file , ImageConfiguration $ config , array $ optional_data = [ ] ) { /* Create ImageFile object for processing */ $ image_file = $ this -> prepareImageFile ( $ framework_file ) ; /* run validation on upload */ $ response = $ this -> validator -> validate ( $ image_file , $ config -> rules ) ; /* if valid create database entry, store image to disk and generate response */ if ( $ response -> success ( ) ) { if ( $ record = $ this -> image_repo -> findExistingImageable ( $ config -> optional_data ) ) { $ this -> image_repo -> delete ( $ record ) ; } $ record = $ this -> image_repo -> create ( [ 'name' => $ config -> image_name , 'disk' => $ config -> temp_disk , 'filename' => $ image_file -> filename , 'path' => $ config -> directory , 'status' => 'pending' , 'width' => $ image_file -> width , 'height' => $ image_file -> height , 'mime_type' => $ image_file -> mime_type , 'extension' => $ image_file -> extension , 'size' => $ image_file -> size , 'alt' => $ optional_data [ 'alt' ] ?? null , 'title' => $ optional_data [ 'title' ] ?? null , 'description' => $ optional_data [ 'description' ] ?? null , ] ) ; $ this -> storage -> put ( $ image_file -> stream , $ record -> disk , "$record->path/$record->uuid" , $ record -> filename ) ; $ response = new StandardServiceResponse ( true , [ 'image' => $ record , ] , 'File successfully uploaded' ) ; } return $ response ; }
Handle Image Upload

@param mixed              $framework_file
@param ImageConfiguration $config
@param array              $optional_data
@return ServiceResponse
Handle Image Upload