PHP code example of feugene / laravel-files

1. Go to this page and download the library: Download feugene/laravel-files library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

feugene / laravel-files example snippets


        // ...
        Feugene\Files\ServiceProvider::class,
    

public function store()
{
    $list = app(UploadService::class)
        ->upload();

    return [
        'success' => $list->isNotEmpty(),
        'files'   => $list,
    ];
}

public function store()
{
    $list = app(UploadService::class)
        ->setAfterAction(AfterModelAction::class)
        ->upload();

    return [
        'success' => $list->isNotEmpty(),
        'files'   => $list,
    ];
}

public function store(int $sectionId)
{
    /** @var Section $section */
    $section = Section::findOrFail($sectionId);

    $this->authorize('uploadFile', $section);

    $upload = new Upload($section);
    $path = $upload->getUploadPath();

    $list = app(UploadService::class)
        ->setPath($path)
        ->setAction(BeforeBaseAction::class, 'before')
        ->setAfterAction(AfterModelAction::class)
        ->setAfterAction(function ($file) use ($section) {
            /** @var \Feugene\Files\Models\File $file */
            
            return File::create([
                'section_id' => $section->id,
                'author_id'  => \Auth::id(),
                'name'       => $file->getBaseFile()->getFilename(),
                'file_id'    => $file->getKey()
            ]);
        })
        ->upload();

    return [
        'success' => $list->isNotEmpty(),
        'files'   => $list,
    ];
}


// find image type from DB
/** @var ImageFile $file */
$file = ImageFile::find($id);

// create child relation with clone image     
$child = $file->createChild();

// Image scale to 50% from original
// without relation
$child = $file->scale(new ScaleModificator(50));
// create child relation 
$child = $file->createChild(new ScaleModificator(50));

// Image resize to 50px by width
// without relation
$child = $file->resize(new ResizeModificator(50));
// create child relation 
$child = $file->createChild(new ResizeModificator(50));


// Image resize to 50px by height
// without relation
$child = $file->resize(new ResizeModificator(null, 50));
// create child relation 
$child = $file->createChild(new ResizeModificator(null, 50));


// Image resize to 50px by height and 100px by width and bestFit options
// without relation
$child = $file->resize(new ResizeModificator(100, 50));
// create child relation 
$child = $file->createChild(new ResizeModificator(100, 50));


// Image resize to 50px by height and 100px by width and important size (100x50)
// without relation
$child = $file->resize(new ResizeModificator(100, 50, false));
$child = $file->resize(new ResizeModificator(100, 50, false), true);  // if original image is smaller than target image
// create child relation 
$child = $file->createChild(new ResizeModificator(100, 50, false));