private function assignImage($field, $filePath, $model) { $file = new File(); $file->fromFile($filePath); if (!is_null($model->{$field}) && strtotime($model->{$field}->updated_at) < filemtime($filePath)) { echo "Update " . $field . " by file " . $file->getFilename() . "\n"; $model->{$field}->delete(); $model->{$field}()->save($file); } }