Looking to hire Laravel developers? Try LaraJobs

laravel-file-model maintained by domatskiy

Description
laravel file model
Last update
2019/03/14 09:57 (dev-dev)
License
Downloads
23

Comments
comments powered by Disqus

Laravel File Model

###Install

composer require domatskiy/laravel-file-model

File

class File extends \Domatskiy\FileModel\CFile
{
    protected $table = 'file';
}
class File extends \Domatskiy\FileModel\CFile
{
    protected $table = 'file';

    protected $path = 'test';

    protected $hidden = array('created_at', 'updated_at');

    protected $fillable = array(
        'file',
    );
}

save file

$file = File::create([
    'file' => new UploadedFile(__DIR__.'/file.txt', 'file.txt'),
]);

####Images

class Image extends \Domatskiy\FileModel\CImage
{
    protected $table = 'file2';
   
    protected $path = 'test2';

    protected static $resize_on_save = false;
    protected $save_max_height = 1200;
    protected $save_max_width = 1200;

    protected $disk_resize = 'public';

    protected $path_resize = 'resize';

    protected $image_quality = 65;
    
    protected $hidden = array('created_at', 'updated_at');

    protected $fillable = array(
        'file',
    );
}

save image and get resize

    $img = Image::create([
        'file' => new UploadedFile(__DIR__.'/abs.jpg', 'abs.jpg'),
    ]);
    
    # get resize
    $rsz = $img
            ->setQuality(80)
            ->getResizeImage(200, 200, $img::RESIZE_PROPORTIONAL);
            
    if ($rsz) {
        $path = $img->getResizeUrl($rsz); 
    }