ahmedkandel / nova-s3-multipart-upload

A Laravel Nova resource tool to upload files directly to Amazon S3. You can (upload | download | delete) single, multiple, small or big files.
MIT License
23 stars 22 forks source link

Field does not display #19

Closed sirmews closed 3 years ago

sirmews commented 3 years ago

Facing the same issue as what was reported on https://github.com/ahmedkandel/nova-s3-multipart-upload/issues/17

I've used your example in the Readme and done the following:

class Media extends Model
{
    protected $fillable = [
        'filename'
    ];

    protected $casts = [
        'filename' => 'array',
    ];

In the equivalent Nova class I've added the following:

    public function fields(Request $request)
    {
        return [
            ID::make(__('ID'), 'id')->sortable(),
            Text::make(__('Title'), 'title')->sortable()->required(),
            NovaS3MultipartUpload::make('Filenames', 'filename')
                ->disk('s3'),

        ];
    }

I can confirm the JS and CSS for the resource tool is being loaded in the browser. There's no policies for this particular model at the moment. Nothing showing up in the browser's console as errors and nothing in my laravel.log. Just doesn't seem to show.

Grateful for any assistance or pointers on what I could possibly be doing wrong.

Laravel version: 8.40 Nova version: 3.26.1

ahmedkandel commented 3 years ago

There is a misconfiguration between the model and nova resource. In the model, you cast the attribute to an array 'filename' => 'array' while in nova resource you didn't use ->storeAsArray($fileKeyColumn) or ->storeAsMultipleArray($fileKeyColumn).

So if you want to upload one single file and save only the filename please remove the casting from your model. Otherwise for multiple files or storing file information please refer to the docs for correct usage of storing as an array.

Also note that ->disk('s3') is not needed as it is default value. While you may need ->keepOriginalName() to store the file by its name, not by a random name.

If you still facing the same issue after fixing your configuration please attach a screenshot to the details page or give me access to it if possible for a better debugging.

sirmews commented 3 years ago

Thanks, I clearly didn't read the docs well enough. Appreciate the assist, that worked.

ahmedkandel commented 3 years ago

Good to hear that