Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save custom fields on model creation #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dive-michiel
Copy link

Hi,

We have a use case where we would like to customize conversions based on custom attributes. To get this working the custom fields need to be saved when the model is created (since the conversions triggers as soon as the model is created).

Here is an example of what we are trying to achieve, but could be any image manipulation based on a custom field:

Images::make('Slideshow', 'slideshow')
    ...
    ->customPropertiesFields([
        Select::make('Crop', 'crop')->options([
            Manipulations::CROP_LEFT => 'Left',
            Manipulations::CROP_CENTER => 'Center',
            Manipulations::CROP_RIGHT => 'Right',
        ])->default(Manipulations::CROP_CENTER),
    ])
    ...
public function registerMediaConversions(Media $media = null): void
{
    $crop = $media->getCustomProperty('crop') ?? Manipulations::CROP_CENTER;

    ...

    $this->addMediaConversion('thumb-two-thirds')
            ->performOnCollections('thumb')
            ->withResponsiveImages()
            ->crop($crop, 580, 870);

    ...

This pull request fixes that problem, if we need to improve or change the code let us know!

✨ Save custom fields on model creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant