PHP code example of rpwebdevelopment / has-image-laravel

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

    

rpwebdevelopment / has-image-laravel example snippets


return [
    'default' => 'local',
];


namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use RPWebDevelopment\HasImageLaravel\Dto\ImageDetails;
use RPWebDevelopment\HasImageLaravel\Traits\HasImage;

class Foo extends Model
{
    use HasImage;
    
    protected $fillable = [
        ...
        'logo',
        ...
    ];

    public function getImageDetails(): ImageDetails
    {
        /**
        * $storageDisk parameter is optional, if excluded the 
        * default disk from your configuration will be accepted.
        *
        * $maintainFilename parameter is optional (false by default)
        * if true, the uploaded file will maintain the original filename
        * as uploaded. If false a hashed filename will be used.
        */
        return ImageDetails::create(
            imageDirectory: 'DIR_NAME',
            imageFields: ['logo'],
            storageDisk: 'public',
            maintainFilename: true
        );
    }
}

bash
php artisan vendor:publish --tag="has-image-laravel-config"