Skip to content

Commit

Permalink
Ability to custom the name or path of the stored file on disk (#72)
Browse files Browse the repository at this point in the history
* Ability to add path in configuration

* Update README.md

* Update README.md

* Fixed code style to support styleci
  • Loading branch information
pitchayakit authored Jan 9, 2023
1 parent 52aa868 commit 87b84b3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ if you want to hide buttons or toolbar you can do this. for more configuration r
| hideTools | Array | ['text-tools', 'block-tools', 'file-tools', 'history-tools'] | hides group of buttons
| hideButtonIcons | Array | ['attach', 'bold', 'italic', 'strike', 'link', 'heading-1', 'quote', 'code', 'bullet-list', 'number-list', 'decrease-nesting-level', 'increase-nesting-level'] | hides a single button
| disk | String | 'local' or 's3' or 'any-disk' | sets the attachment storage per field
| path | String | 'any-path' | customize the name or path of the stored file on disk
| id | String | 'any-value-you-want' | the id of input which renders [trix. check this link](https://github.com/basecamp/trix#integrating-with-forms) . current id follows this convention `(model lowered class name)-field-modelId` like `post-content-1` or `post-content-new-model`
| containerElement | String | valid html tag like `span` or `div` | default container tag is set to `span` you can change it as you want

Expand Down
4 changes: 4 additions & 0 deletions resources/views/trixassets.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ function createFormData(data) {
formData.append("disk", data.disk);
}
if(data.path != undefined) {
formData.append("path", data.path);
}
return formData;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/TrixAttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function store(Request $request)
return response()->json(['errors'=>$validator->errors()], Response::HTTP_UNPROCESSABLE_ENTITY);
}

$attachment = $request->file->store('/', $request->disk ?? config('laravel-trix.storage_disk'));
$attachment = $request->file->store($request->path ?? '/', $request->disk ?? config('laravel-trix.storage_disk'));

$url = Storage::disk($request->disk ?? config('laravel-trix.storage_disk'))->url($attachment);

Expand All @@ -39,7 +39,7 @@ public function store(Request $request)

public function destroy($url)
{
$attachment = TrixAttachment::where('attachment', basename($url))->first();
$attachment = TrixAttachment::where('attachment', 'LIKE', '%'.basename($url))->first();

return response()->json(optional($attachment)->purge());
}
Expand Down

0 comments on commit 87b84b3

Please sign in to comment.