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

Allow upload to replace file #283

Merged
merged 2 commits into from
Aug 8, 2023
Merged

Conversation

mikaelpopowicz
Copy link
Collaborator

This PR adds ability to replace file when uploading a file with an existing file name.

It adds a configuration option upload_replace_existing, when set to true it allows upload to replace existing file.

It also adds the new uploadReplaceExisting method on field, tool and wrapper to configure it programmatically

// app/Nova/Project.php

use Oneduo\NovaFileManager\FileManager;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
use Laravel\Nova\Http\Requests\NovaRequest;

class Project extends Resource
{
    // ...

    public function fields(NovaRequest $request): array
    {
        return [
            // ... any other fields
            FileManager::make(__('Attachments'), 'attachments')
                ->uploadReplaceExisting(function (NovaRequest $request): bool {
                    return true;
                }),
        ];
    }
}

Closes #268

@mikaelpopowicz mikaelpopowicz linked an issue Aug 8, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.46% 🎉

Comparison is base (f1d43b4) 71.87% compared to head (0c11f54) 72.34%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #283      +/-   ##
============================================
+ Coverage     71.87%   72.34%   +0.46%     
- Complexity      270      274       +4     
============================================
  Files            44       44              
  Lines           889      904      +15     
============================================
+ Hits            639      654      +15     
  Misses          250      250              
Files Changed Coverage Δ
src/Http/Requests/UploadFileRequest.php 100.00% <100.00%> (ø)
src/Traits/Support/InteractsWithFilesystem.php 72.68% <100.00%> (+1.02%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@Rezrazi Rezrazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

@Rezrazi Rezrazi merged commit 275ce05 into main Aug 8, 2023
13 checks passed
@Rezrazi Rezrazi deleted the 238-allow-replace-files-same-name branch August 8, 2023 16:43
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.

Allow replace files same name
2 participants