src/Engine/Helpers/CrudeFiles.php
public function delete($model, $log, $fileAttrName = 'files', $fileLogId = 0)
    {
        $updatedFiles = [];
        if ($log)
            $fileLogId = $log->id;

        $fileToDelete = [];
        foreach ($model->files as $file) {
            if ($file['file_log_id'] == $fileLogId)
                $fileToDelete = $file;
            else
                $updatedFiles[] = $file;
        }

        if ($log)
            Storage::delete($log->file_path);
        else
            Storage::delete($fileToDelete['path']);

        if ($log)
            $log->delete();

        $model->$fileAttrName = $updatedFiles;
        return $model;
    }
public function delete($model, $log, $fileAttrName = 'files', $fileLogId = 0)
    {
        $updatedFiles = [];
        if ($log)
            $fileLogId = $log->id;

        $fileToDelete = [];
        foreach ($model->files as $file) {
            if ($file['file_log_id'] == $fileLogId)
                $fileToDelete = $file;
            else
                $updatedFiles[] = $file;
        }

        if ($log)
            Storage::delete($log->file_path);
        else
            Storage::delete($fileToDelete['path']);

        if ($log)
            $log->delete();

        $model->$fileAttrName = $updatedFiles;
        return $model;
    }
public function delete ( $ model , $ log , $ fileAttrName = 'files' , $ fileLogId = 0 ) { $ updatedFiles = [ ] ; if ( $ log ) $ fileLogId = $ log -> id ; $ fileToDelete = [ ] ; foreach ( $ model -> files as $ file ) { if ( $ file [ 'file_log_id' ] == $ fileLogId ) $ fileToDelete = $ file ; else $ updatedFiles [ ] = $ file ; } if ( $ log ) Storage :: delete ( $ log -> file_path ) ; else Storage :: delete ( $ fileToDelete [ 'path' ] ) ; if ( $ log ) $ log -> delete ( ) ; $ model -> $ fileAttrName = $ updatedFiles ; return $ model ; }
Delete file for model, without save model
@param  Model $model
@param  FileLog $log
@param  String $fileAttrName = 'files'
@param  String $fileLogId = 0 - used when log is missing
@return Model
Delete file for model without save model