FabCol's avatar

One field to upload either image or pdf

Hi all,

Is there a way in form to have ONE field which will either accept images or pdf?

I'm currently doing that using 2 fields... which doesn't fit exactly my needs...

I tried:

     public function rules()
        {
        return [
            'name' => 'required',
            'doc' => 'nullable|mimes:png,jpg,jpeg,gif,pdf',
        ];
    }

and public function store(StoreDocumentsRequest $request) { $request = $this->saveFiles($request); $document = Document::create($request->all());

    return redirect()->route('documents.index');
}

And I'm getting a beautiful:

Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.

Any idea? I found nothing so far...

Thanks

0 likes
2 replies
FabCol's avatar

Ho, I also tried in my blade:

In my blade:

<div>
    {!! Form::file('photo, pdf', ['class' => 'form-control', 'style' => 'margin-top: 4px;']) !!}
    {!! Form::hidden('photo_max_size', 8) !!}
    {!! Form::hidden('photo_max_width', 6000) !!}
     {!! Form::hidden('photo_max_height', 6000) !!}
</div>

Then no error but nothing in the ddb :-/

FabCol's avatar

OK, I'm starting to understand indeed... I need to write the trait myself I guess... working on it now.

Please or to participate in this conversation.