Skip to content

Commit 26a6b28

Browse files
committed
updated readme
1 parent 1cd6ba3 commit 26a6b28

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

README.md

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,35 @@ class User extends Model {
137137
//...
138138
]
139139
];
140+
141+
// any other than image file type for upload
142+
protected static $fileFields = [
143+
'resume' => [
144+
// what disk you want to upload, default config('imageup.upload_disk')
145+
'disk' => 'public',
146+
147+
// a folder path on the above disk, default config('imageup.upload_directory')
148+
'path' => 'docs',
149+
150+
// validation rules when uploading file
151+
'rules' => 'mimes:doc,pdf,docx|max:1000',
152+
153+
// override global auto upload setting coming from config('imageup.auto_upload_images')
154+
'auto_upload' => false,
155+
156+
// if request file is don't have same name, default will be the field name
157+
'file_input' => 'cv',
158+
159+
// a hook that is triggered before the file is saved
160+
'before_save' => HookForBeforeSave::class,
161+
162+
// a hook that is triggered after the file is saved
163+
'after_save' => HookForAfterSave::class
164+
],
165+
'cover_letter' => [
166+
//...
167+
]
168+
];
140169
}
141170
```
142171
### Customize filename
@@ -189,38 +218,46 @@ You are not limited to use auto upload image feature only. This trait will give
189218
on model or by calling `$model->setImagesField(['cover' => ['auto_upload' => false]);`
190219
otherwise you will be not seeing your manual uploads, since it will be overwritten by auto upload upon model save.
191220

192-
#### $model->uploadImage($imageFile, $field = null)
221+
#### $model->uploadImage($imageFile, $field = null) / $model->uploadFile($docFile, $field = null)
193222

194-
Upload image for given $field, if $field is null it will upload to first image option defined in array.
223+
Upload image/file for given $field, if $field is null it will upload to first image/file option defined in array.
195224

196225
```php
197226
$user = User::findOrFail($id);
198227
$user->uploadImage(request()->file('cover'), 'cover');
228+
$user->uploadFile(request()->file('resume'), 'resume');
199229
```
200230

201-
#### $model->setImagesField($fieldsOptions)
231+
#### $model->setImagesField($fieldsOptions) / $model->setFilesField($fieldsOptions)
202232

203-
You can also set the image fields dynamically by calling `$model->setImagesField($fieldsOptions)` with field options, it will replace fields defined on model property.
233+
You can also set the image/file fields dynamically by calling `$model->setImagesField($fieldsOptions) / $model->setFilesField($fieldsOptions)` with field options, it will replace fields defined on model property.
204234

205235
```php
206236
$user = User::findOrFail($id);
207237

208238
$fieldOptions = [
209239
'cover' => [ 'width' => 1000 ],
210-
'avatar' => [ 'width' => 120, 'crop' => true ]
240+
'avatar' => [ 'width' => 120, 'crop' => true ],
211241
];
212242

213243
// override image fields defined on model
214244
$user->setImagesField($fieldOptions);
245+
246+
$fileFieldOption = [
247+
'resume' => ['path' => 'resumes']
248+
];
249+
250+
// override file fields defined on model
251+
$user->setFilesField($fileFieldOption);
215252
```
216253

217-
#### $model->hasImageField($field)
254+
#### $model->hasImageField($field) / $model->hasFileField($field)
218255

219-
To check if field is defined as image field.
256+
To check if field is defined as image/file field.
220257

221-
#### $model->deleteImage($filePath)
258+
#### $model->deleteImage($filePath) / $model->deleteFile($filePath)
222259

223-
Delete any image if it exists.
260+
Delete any image/file if it exists.
224261

225262
#### $model->resizeImage($imageFile, $fieldOptions)
226263

@@ -260,9 +297,9 @@ $user->cropTo($coords)
260297
->uploadImage(request()->file('cover'), 'avatar');
261298
```
262299

263-
#### $model->imageUrl($field)
300+
#### $model->imageUrl($field) / $model->fileUrl($field)
264301

265-
Gives uploaded image url for given image field.
302+
Gives uploaded file url for given image/file field.
266303

267304
```php
268305
$user = User::findOrFail($id);

0 commit comments

Comments
 (0)