Skip to content

Commit

Permalink
fix(upload): fix an issue where a file could not be uploaded in a sub…
Browse files Browse the repository at this point in the history
…directory when a file with same name exists in the root directory
  • Loading branch information
mikaelpopowicz committed Sep 10, 2022
1 parent 5144db6 commit e9c1f6a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Rules/FileMissingInFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace BBSLab\NovaFileManager\Rules;

use BBSLab\NovaFileManager\Http\Requests\BaseRequest;
use BBSLab\NovaFileManager\Http\Requests\UploadFileRequest;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Str;

class FileMissingInFilesystem implements Rule
{
public ?string $path = null;

public function __construct(public BaseRequest $request)
public function __construct(public UploadFileRequest $request)
{
}

Expand All @@ -22,16 +23,16 @@ public function __construct(public BaseRequest $request)
*/
public function passes($attribute, $value): bool
{
$this->path = $value->getClientOriginalName();
$this->path = Str::finish($this->request->path, '/').$value->getClientOriginalName();

return $this->request
->manager()
->filesystem()
->missing($value->getClientOriginalName());
->missing($this->path);
}

public function message(): string
{
return __('nova-file-manager::validation.path.missing', ['path' => $this->path]);
return __('nova-file-manager::validation.path.exists', ['path' => $this->path]);
}
}

0 comments on commit e9c1f6a

Please sign in to comment.