PHP code example of saad / laravel-model-images

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

    

saad / laravel-model-images example snippets

 php

// ProfilesController.php File
class ProfilesController
{		
    // Save Image From Upload Request    
    public function setUserProfile(Request $request, User $user) {
        // You can Validate
        $image = $request->file('image');
        if ($image) {
            $user->image = $image;
        }
        
        $user->save();
    }
    
    // Set Image from image file on storage
    public function setUserProfile() {
        $user = User::find(1);
        $user->image = storage_path('app/images/profile.png');
        $user->save();
    }
}
 php
		
// User.php File
class User extends Autheticatable implements ImageableContract
{
    use HasImages;
    ...
    public function imageSaveExtension() :string
    {
        return 'png';
    }
    
    public function imageSaveQuality() :int
    {
        return 7;
    }
    
    public function imagePNGFilter() :int
    {
        return PNG_ALL_FILTERS;
    }
}