PHP code example of takdw / nova-advanced-image-field

1. Go to this page and download the library: Download takdw/nova-advanced-image-field 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/ */

    

takdw / nova-advanced-image-field example snippets




namespace App\Nova;

// ...
use Illuminate\Http\Request;
use Ctessier\NovaAdvancedImageField\AdvancedImage;

class Post extends Resource
{
    // ...

    public function fields(Request $request)
    {
        return [
            // ...

            // Simple image upload
            AdvancedImage::make('Photo'),

            // Show a cropbox with a free ratio
            AdvancedImage::make('Photo')->croppable(),

            // Show a cropbox with a fixed ratio
            AdvancedImage::make('Photo')->croppable(16/9),

            // Resize the image to a max width
            AdvancedImage::make('Photo')->resize(1920),

            // Resize the image to a max height
            AdvancedImage::make('Photo')->resize(null, 1080),

            // Show a cropbox and resize the image
            AdvancedImage::make('Photo')->croppable()->resize(400, 300),

            // Override the image processing driver for this field only
            AdvancedImage::make('Photo')->driver('imagick')->croppable(),

            // Store to AWS S3
            AdvancedImage::make('Photo')->disk('s3'),

            // Specify a custom subdirectory
            AdvancedImage::make('Photo')->croppable()->disk('s3')->path('image'),

            // Store custom attributes
            AdvancedImage::make('Photo')->croppable()->store(function (Request $request, $model) {
                return [
                    'photo' => $request->photo->store('/', 's3'),
                    'photo_mime' => $request->photo->getMimeType(),
                    'photo_name' => $request->photo->getClientOriginalName(),
                ];
            }),
        ];
    }
}