PHP code example of padosoft / laravel-uploadable

1. Go to this page and download the library: Download padosoft/laravel-uploadable 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/ */

    

padosoft / laravel-uploadable example snippets




namespace App;

use Padosoft\Uploadable\Uploadable;
use Padosoft\Uploadable\UploadOptions;
use Illuminate\Database\Eloquent\Model;

class YourEloquentModel extends Model
{
    use Uploadable;
    
 /**
     * Retrive a specifice UploadOptions for this model, or return default UploadOptions
     * @return UploadOptions
     */
    public function getUploadOptions() : UploadOptions
    {
        if($this->uploadOptions){
            return $this->uploadOptions;
        }

        $this->uploadOptions = UploadOptions::create()->getUploadOptionsDefault()
            ->setUploadBasePath(public_path('upload/' . $this->getTable()))
            ->setUploadsAttributes(['image', 'image_mobile']);

        return $this->uploadOptions;
    }
}

public function getUploadOptions() : UploadOptions
{
    return UploadOptions::create()
        ->setUploadsAttributes(['image', 'image_mobile']);
}

public function getUploadOptions() : UploadOptions
{
    return UploadOptions::create()
        ->setUploadBasePath(public_path('upload/news'));
}

public function getUploadOptions() : UploadOptions
{
    return UploadOptions::create()
        ->setUploadPaths(['image_mobile' => '/mobile' ]);
}

public function getUploadOptions() : UploadOptions
{
    return UploadOptions::create()
        ->setMimeType([
          'image/gif',
          'image/jpeg',
          'image/png',
            ]);
}

/**
 * Generate a new file name for uploaded file.
 * Return empty string if $uploadedFile is null.
 * @param \Illuminate\Http\UploadedFile $uploadedFile
 * @param String $uploadField
 * @return string
 */
public function generateNewUploadFileName(\Illuminate\Http\UploadedFile $uploadedFile, string $uploadField) : string 
{
    if($uploadField=='image'){
        return 'pippo.jpg';
    }else{
        return 'pippo_mobile.jpg';
    }
}

public function getUploadOptions() : UploadOptions
{
    return UploadOptions::create()
        ->setStorageDisk('ftp');
}