PHP code example of johntout / laravel-image-sizes

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

    

johntout / laravel-image-sizes example snippets


class User extends Model 
{
    use JohnTout\LaravelImageSizes\HasMedia;
    
    public string filesystem_disk = 'avatars';
    
    public string image_field = 'avatar';
    
    // OR
    
    /**
     * @return Attribute
     */
    public function filesystemDisk(): Attribute
    {
        return Attribute::make(
            get: fn () => 'avatars'
        );
    }

    /**
     * @return Attribute
     */
    public function imageField(): Attribute
    {
        return Attribute::make(
            get: fn () => 'avatar'
        );
    }
}

$user = User::query()->find(1);
$user->saveImage($request->file('image'));

$user->imageUrl(size: 'originalImage');

PHP 8+
Laravel 9+

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