https://twill.io logo
Medias field error and image rendering
# ❓questions
n
Hi, I have a simple form where I have a title and a
medias
field which holds an image, and everytime I try to save the new picture, it fails with this error
Your submission could not be validated, please fix and retry
. I tried setting up the $mediasParams array correctly, but it seems like it has no effect. I believe that the model is setup correctly because it saves the title when the image field is not there to throw an error. What else do I need to setup to save the selectd image?
i
Hi @Nechalon what is the name of your medias field?
n
Copy code
public $mediasParams = [
        'background_desktop' => [
            'desktop' => [
                [
                    'name' => 'desktop',
                    'ratio' => 0,
                ],
            ],
            'mobile' => [
                [
                    'name' => 'mobile',
                    'ratio' => 4/3,
                ],
            ]
        ],
    ];
background_desktop
and thats the same for the medias here
Copy code
@formField('medias', [
        'name' => 'background_desktop',
        'label' => __('form.newsletter_background_desktop'),
    ])
i
does you repository have the HandleMedias trait and does your model have the HasMedias trait?
n
I added those too
k
Check laravel log file or network request, it should return full 500 error. So we can check whats really the problem.
n
I answered no to all questions when I was generating the twill module, but then later I added those
I checked it, it has several arrays and it looks like that the image is there. I also noticed in exceptions that it fails with
The given data was invalid.
error message and shows
failedValidation
function. Is it possible that it fails because of the [Module]Request.php?
I have removed the line where I require the image table column, and now it saved it but the "image" column is empty in DB
i
there is no need for any column in your model to save a medias field
n
Ok, then how can I get the saved image if I want to display it somewhere?
just use renderBlocks?
i
renderBlocks is to render blocks, not images,
$item->image('background_desktop', 'desktop')
would render it
n
Just a quick question, what could be the problem if the mediasParams array' crop modes are not displayed? I have added one named
desktop
and one named
mobile
, none of them are shown.
ratio
array key does work because it changes the aspect ratio of the picture.
i
with the configuration you pasted earlier, you should see two tabs (or "pills") at the top of the cropping modal, one for your desktop crop and one for your mobile crop
n
Im using that configuration, and I have seen those pills before, here its just not there
i
is this medias field on the form itself or in a block?
n
its in an a17-fieldset and it is a medias field
@ifox 😄
i
I can't reproduce this. Can you share you model and form?
n
Here it is
i
I mean, this looks good
do you have some crops config defined in twill.php for blocks?
asking because they might conflict
n
Yes I have, should I delete them and try it?
tried it, looks the same
i
did you try removing and adding the image again? Not in the media library, I mean in the field itself
n
I did just that, removed it, added another one, and now it looks like its good, the crop modes are now there, thanks @ifox 😄
i
ok so yeah if you change the mediasParams you either need to do that, or use the refresh-crops artisan command
3 Views