You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 7.x-dev/crud-fields.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -874,7 +874,7 @@ CRUD::field([
874
874
875
875
#### Uploading files with summernote
876
876
877
-
Summernote saves images as base64 encoded strings in the database. If you want to save them as files on the server, you can use the [Summernote File Upload](https://backpackforlaravel.com/docs/7.x/crud-uploaders). Please note that the Summernote Uploader is part of the `backpack/pro` package.
877
+
Summernote saves images as base64 encoded strings in the database. If you want to save them as files on the server, you can use the [Summernote Uploader](https://backpackforlaravel.com/docs/7.x/crud-uploaders). Please note that the Summernote Uploader is part of the `backpack/pro` package.
878
878
Input preview:
879
879
880
880

Copy file name to clipboardExpand all lines: 7.x-dev/crud-uploaders.md
+18-15Lines changed: 18 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,12 @@ We've already created Uploaders for the most common scenarios:
70
70
71
71
Do you want to create your own Uploader class, for your custom field? Here's how you can do that, and how Uploader classes work behind the scenes.
72
72
73
-
First thing you need to decide if you need "Ajax" or "Non-Ajax" upload. The big difference is that the "non-ajax" uploaders process the file upload when you submit your form, while the ajax upload process the file using a javascript ajax request, so it can be uploaded before you submit the form.
73
+
First thing you need to decide if you are creating a _non-ajax_ or _ajax_ uploader:
74
+
-_non-ajax_ uploaders process the file upload when you submit your form;
75
+
-_ajax_ uploaders process the file upload before the form is submitted, by submitting an AJAX request using Javascript;
But most likely, you have a `custom_upload` field that you'd like to use this uploader without having to specify it every time. You can do that by adding it to the `UploadersRepository`in your Service Provider `boot()` method:
115
+
If you custom uploader was created to work for a custom field (say it's called `custom_upload`), you can tell Backpack to always use this uploader for that field type - that way you don't have to specify it every time you use the field. You can do that in your Service Provider `boot()` method, by adding it to the `UploadersRepository`:
111
116
112
117
```php
113
118
// in your App\Providers\AppServiceProvider.php
@@ -118,11 +123,11 @@ protected function boot()
118
123
}
119
124
```
120
125
121
-
You can now use `CRUD::field('avatar')->type('custom_upload')->withFiles();` and it will use your custom uploader. What happen behind the scenes is that Backpack will register your uploader to be ran in 3 different model events: `saving`, `retrieved` and `deleting`.
126
+
You can now use `CRUD::field('avatar')->type('custom_upload')->withFiles();` and it will use your custom uploader. What happens behind the scenes is that Backpack will register your uploader to run on 3 different model events: `saving`, `retrieved` and `deleting`.
122
127
123
128
The `Uploader` class has 3 "entry points" for the mentioned events: **`storeUploadedFiles()`**, **`retrieveUploadedFiles()`** and **`deleteUploadedFiles()`**. You can overwrite these methods in your custom uploader to add your custom logic but for most uploaders you will not need to overwrite them as they are "setup" methods for the action that will be performed, and after setup they call the relevant methods that each uploader will implement, like ```uploadFiles()``` or ```uploadRepeatableFiles()```.
124
129
125
-
The base uploader class has most of the functionality implemented and use**"strategy methods"** to configure the underlying behavior.
130
+
Notice this custom class you're creating is extending `Backpack\CRUD\app\Library\Uploaders\Uploader`. That base uploader class has most of the functionality implemented and uses**"strategy methods"** to configure the underlying behavior.
126
131
127
132
**`shouldUploadFiles`** - a method that returns a boolean to determine if the files should be uploaded. By default it returns true, but you can overwrite it to add your custom logic.
128
133
@@ -152,9 +157,11 @@ protected function shouldUploadFiles($value): bool
152
157
// when the value is an instance of UploadedFile, it means the file was uploaded and we should upload it
For the ajax uploaders, the process is similar, but the `CustomUploader` class should extend `BackpackAjaxUploader`**(requires backpack/pro)** instead of `Uploader`.
For the ajax uploaders, the process is similar, but your custom uploader class should extend `BackpackAjaxUploader` instead of `Uploader` (**note that this requires backpack/pro**).
158
165
159
166
```php
160
167
@@ -186,15 +193,11 @@ In addition to the field configuration, ajax uploaders require that you use the
186
193
Similar to model events, there are two "setup" methods for those endpoints: **`processAjaxEndpointUploads()`** and **`deleteAjaxEndpointUpload()`**. You can overwrite them to add your custom logic but most of the time you will not need to do that and just implement the `uploadFiles()` and `uploadRepeatableFiles()` methods.
187
194
188
195
The ajax uploader also has the same "strategy methods" as the non-ajax uploader (see above), but adds a few more:
189
-
**`ajaxEndpointSuccessResponse($files = null)`** - this should return a `JsonResponse` with the needed information when the upload is successful. By default it returns a json response with the file path.
190
-
191
-
**`ajaxEndpointErrorResponse($message)`** - use this method to change the endpoint response in case the upload failed. Similar to the success it should return a `JsonResponse`.
192
-
193
-
**`getAjaxEndpointDisk()`** - by default a `temporaryDisk` is used to store the files before they are moved to the final disk. (when uploadFiles() is called). You can overwrite this method to change the disk used.
194
-
195
-
**`getAjaxEndpointPath()`** - by default the path is `/temp` but you can overwrite this method to change the path used.
196
-
197
-
**`getDefaultAjaxEndpointValidation()`** - Should return the default validation rules (in the format of `BackpackCustomRule`) for the ajax endpoint. By default it returns a `ValidGenericAjaxEndpoint` rule.
196
+
-**`ajaxEndpointSuccessResponse($files = null)`** - This should return a `JsonResponse` with the needed information when the upload is successful. By default it returns a json response with the file path.
197
+
-**`ajaxEndpointErrorResponse($message)`** - Use this method to change the endpoint response in case the upload failed. Similar to the success it should return a `JsonResponse`.
198
+
-**`getAjaxEndpointDisk()`** - By default a `temporaryDisk` is used to store the files before they are moved to the final disk (when uploadFiles() is called). You can overwrite this method to change the disk used.
199
+
-**`getAjaxEndpointPath()`** - By default the path is `/temp` but you can override this method to change the path used.
200
+
-**`getDefaultAjaxEndpointValidation()`** - Should return the default validation rules (in the format of `BackpackCustomRule`) for the ajax endpoint. By default it returns a `ValidGenericAjaxEndpoint` rule.
198
201
199
202
200
203
For any other customization you would like to perform, please check the source code of the `Uploader` and `BackpackAjaxUploader` classes.
0 commit comments