PHP code example of cbcaio / image-attacher

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

    

cbcaio / image-attacher example snippets


        $upload = Input::file('image');
        $model->addImage($upload);
         // Directly from $request
        $model->addImage($request->file('image'));
         // With parameters
        $model->addImage($request->file('image', 'processing_style_routine','newfilename.jpg'));
    

        $image = $user->getImage();
          // Path is relative
        $image->getPath('original_style);
        $image->getPath('thumbnail);
        
          // Url 

        // The same as adding, the package will identify if the model already has an image, delete the previous 
        images and update the relationship.
        $upload = Input::file('image2');
        $model->addImage($upload);
    

        $model->deleteImage();
    
 bash
$ php artisan vendor:publish

             $model->addImage(uploaded_file,'default_routine');
             ....
              'default_routine' =>
              [
                  'original_style' => function ($image) {
                      return $image;
                  },
                  'thumbnail' => function ($image) {
                     $image->resize(null, 500, function ($constraint) {
                         $constraint->aspectRatio();
                         $constraint->upsize();
                     });
                     return $image;
                  },
              ]