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

with nova I want to uplpad a file to s3 to 'ly/contents', but it was created in the root dir. #3729

Open
Eternal37 opened this issue Nov 21, 2024 · 0 comments

Comments

@Eternal37
Copy link

Image

            File::make(__('Attachment'), 'attachment')
                ->acceptedTypes('.pdf')
                ->disk('s3')
                ->path('ly/contents')
                ->store(function (Request $request, $model) {
                    $s3filePath = $request->attachment->store('ly/contents', 's3');
                    $model
                        ->addMediaFromDisk($s3filePath, 's3')
                        ->toMediaCollection('pdf');
                    return [
                        'attachment' => $s3filePath
                    ];
                })->onlyOnForms(),

# I have no attachment field in the database, so I use next fillFields function to fix this.

    // https://github.com/laravel/nova-issues/issues/2334#issuecomment-709422756
    protected static function fillFields(NovaRequest $request, $model, $fields)
        {
            $fillFields = parent::fillFields($request, $model, $fields);

            // first element should be model object
            $modelObject = $fillFields[0];

            // remove all attributes do not have relevant columns in model table
            unset($modelObject->attachment);

            return $fillFields;
        }
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

No branches or pull requests

1 participant