File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,31 @@ public function saveInto($column = null, $saveAsArray = false)
148148 return false ;
149149 }
150150
151+ /**
152+ * Save the particular file path into the model property and delete the old resource
153+ *
154+ * @param string $column
155+ * @return bool
156+ *
157+ */
158+ public function updateInto ($ column = null )
159+ {
160+ $ column_name = $ column ?? $ this ->request_input_field ;
161+
162+ // remove old res
163+
164+ $ file = public_path ($ this ->$ column_name );
165+ if (is_file ($ file )) {
166+ unlink ($ file );
167+ }
168+
169+ if (count ($ this ->uploaded_files )) {
170+ $ this ->$ column_name = $ this ->uploaded_files [0 ];
171+ return $ this ->save ();
172+ }
173+ return false ;
174+ }
175+
151176
152177 /**
153178 * Get all the uploaded files path as array
@@ -170,9 +195,7 @@ public function getUploadedFiles()
170195 public function deleteWith ($ column ): bool
171196 {
172197 $ file = public_path ($ this ->$ column );
173- if (is_file ($ file )) {
174- unlink ($ file );
175- }
198+ if (is_file ($ file )) unlink ($ file );
176199 return $ this ->delete ();
177200 }
178201}
You can’t perform that action at this time.
0 commit comments