PHP code example of kingofcode / laravel-uploadable

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

    

kingofcode / laravel-uploadable example snippets


use KingOfCode\Upload\Uploadable;

class Product extends Model
{
    use Uploadable;

    protected $fillable = [
        'name',
        'type',
        // Avoid adding file fields in the fillable array, it can break the correct upload
    ];
    
    // Array of uploadable images. These fields need to be existent in your database table
    protected $uploadableImages = [
        'image',
        'perfil_image',
        'test_image'
    ];
    
    // Array of uploadable files. These fields need to be existent in your database table
    protected $uploadableFiles = [
        'pdf'
    ];

}

protected $uploadableImages = [
  'image' => ['thumb' => 150, 'medium' => 500, 'normal' => 700],
  'perfil_image' => ['thumb' => 120, 'medium' => 'image_width', normal => 2000],
  'test_image'
];

protected $imageResizeTypes = [
  'medium' => false,
  // ... You can disable medium and normal images upload too
];

public $uploadFolderName = 'products'; // Name of your folder


$product = Product::find(1);

$normal_image = $product->getImagePath('image');
$thumb_image = $product->getImagePath('image', 'thumb');
$medium_perfil_image = $product->getImagePath('perfil_image', 'medium');



$product = Product::find(1);

$pdf = $product->getFilePath('pdf');


php artisan storage:link