Nova Canvas Help

Image uploads

Set the disk

By default, Canvas will attempt to use the disk defined in nova.storage-disk config.

You can override this using the ->disk(...) method:

Canvas::make('Content') ->disk('public')

You can also pass a path as the optional second parameter:

Canvas::make('Content') ->disk('public', 'images')

Optimisation

Canvas uses Spatie image optimizer to automatically optimise uploaded images, which is essential for performance on your applications front-end.

Configure image optimisation

  1. Publish the config file:

    php artisan vendor:publish --provider="Spatie\LaravelImageOptimizer\ImageOptimizerServiceProvider"
  2. Update config/image-optimizer.php

Using your own endpoint

The built-in endpoint should work fine for most use-cases, but its completely replaceable if you want to add additional functionality.

You can simply change the endpoint path in the nova-canvas.images.endpoint config.

Your endpoint should accept a POST request with the following:

  • $_FILE (image) - The image to upload.

  • $_POST (disk) - The disk to upload images to.

  • $_POST (path) - The path to upload images to.

If the upload is successful it should respond with 200 OK and a public path to the uploaded image as JSON:

{ "path": "images/my-image.jpg" }

If something goes wrong it should respond with 422 Unprocessable Content or 500 Internal Server Error, you can also provide an error message as JSON:

{ "error": "Image must be smaller than 10MB" }
Last modified: 11 September 2024