classes/Models/Element.php
public function defaultImage()
    {
        // Return an empty Image object if no default value
        if (empty($this->value)) {
            return new Image;
        }

        // All src images must live in the /img (relative) directory
        if (!Str::is('/img/*', $this->value)) {
            $msg = 'Element images must be stored in public/img: '.$this->value;
            throw new Exception($msg);
        }

        // Check if the image already exists in the uploads directory
        $src = $this->value;
        $src_abs = public_path($src);
        $path = str_replace('/img/', '/elements/', $src);
        if (!app('upchuck.disk')->has($path)) {

            // Copy it to the disk
            $stream = fopen($src_abs, 'r+');
            app('upchuck.disk')->writeStream($path, $stream);
            fclose($stream);
        }

        // Wrap the touching of the element and images table in a transaction
        // so that the element isn't updated if the images write fails
        DB::beginTransaction();

        // Update or create this Element instance
        $this->value = app('upchuck')->url($path);
        $this->save();

        // Create and return new Image instance. The Image::populateFileMeta()
        // requires an UploadedFile, so we need to do it manually here.
        $size = getimagesize($src_abs);
        $image = new Image([
            'file' => $this->value,
            'name' => $this->inputName(),
            'file_type' => pathinfo($src_abs, PATHINFO_EXTENSION),
            'file_size' => filesize($src_abs),
            'width'     => $size[0],
            'height'    => $size[1],
        ]);
        $this->images()->save($image);
        DB::commit();

        // Clear cached image relations
        unset($this->relations['images']);

        // Return the image
        return $image;
    }
public function defaultImage()
    {
        // Return an empty Image object if no default value
        if (empty($this->value)) {
            return new Image;
        }

        // All src images must live in the /img (relative) directory
        if (!Str::is('/img/*', $this->value)) {
            $msg = 'Element images must be stored in public/img: '.$this->value;
            throw new Exception($msg);
        }

        // Check if the image already exists in the uploads directory
        $src = $this->value;
        $src_abs = public_path($src);
        $path = str_replace('/img/', '/elements/', $src);
        if (!app('upchuck.disk')->has($path)) {

            // Copy it to the disk
            $stream = fopen($src_abs, 'r+');
            app('upchuck.disk')->writeStream($path, $stream);
            fclose($stream);
        }

        // Wrap the touching of the element and images table in a transaction
        // so that the element isn't updated if the images write fails
        DB::beginTransaction();

        // Update or create this Element instance
        $this->value = app('upchuck')->url($path);
        $this->save();

        // Create and return new Image instance. The Image::populateFileMeta()
        // requires an UploadedFile, so we need to do it manually here.
        $size = getimagesize($src_abs);
        $image = new Image([
            'file' => $this->value,
            'name' => $this->inputName(),
            'file_type' => pathinfo($src_abs, PATHINFO_EXTENSION),
            'file_size' => filesize($src_abs),
            'width'     => $size[0],
            'height'    => $size[1],
        ]);
        $this->images()->save($image);
        DB::commit();

        // Clear cached image relations
        unset($this->relations['images']);

        // Return the image
        return $image;
    }
public function defaultImage ( ) { // Return an empty Image object if no default value if ( empty ( $ this -> value ) ) { return new Image ; } // All src images must live in the /img (relative) directory if ( ! Str :: is ( '/img/*' , $ this -> value ) ) { $ msg = 'Element images must be stored in public/img: ' . $ this -> value ; throw new Exception ( $ msg ) ; } // Check if the image already exists in the uploads directory $ src = $ this -> value ; $ src_abs = public_path ( $ src ) ; $ path = str_replace ( '/img/' , '/elements/' , $ src ) ; if ( ! app ( 'upchuck.disk' ) -> has ( $ path ) ) { // Copy it to the disk $ stream = fopen ( $ src_abs , 'r+' ) ; app ( 'upchuck.disk' ) -> writeStream ( $ path , $ stream ) ; fclose ( $ stream ) ; } // Wrap the touching of the element and images table in a transaction // so that the element isn't updated if the images write fails DB :: beginTransaction ( ) ; // Update or create this Element instance $ this -> value = app ( 'upchuck' ) -> url ( $ path ) ; $ this -> save ( ) ; // Create and return new Image instance. The Image::populateFileMeta() // requires an UploadedFile, so we need to do it manually here. $ size = getimagesize ( $ src_abs ) ; $ image = new Image ( [ 'file' => $ this -> value , 'name' => $ this -> inputName ( ) , 'file_type' => pathinfo ( $ src_abs , PATHINFO_EXTENSION ) , 'file_size' => filesize ( $ src_abs ) , 'width' => $ size [ 0 ] , 'height' => $ size [ 1 ] , ] ) ; $ this -> images ( ) -> save ( $ image ) ; DB :: commit ( ) ; // Clear cached image relations unset ( $ this -> relations [ 'images' ] ) ; // Return the image return $ image ; }
Check if the value looks like an image.  If it does, copy it to the uploads
dir so Croppa can work on it and return the modified path

@return Image
Check if the value looks like an image . If it does copy it to the uploads dir so Croppa can work on it and return the modified path