src/Engine/Helpers/CrudeFiles.php
public function upload($model, $folderName, $files, $fileAttrName = 'files', $width = null)
    {
        $updatedFiles = $model->$fileAttrName;

        foreach ($files as $file) {

            $log = (new FileLog)->create([
                'model_id' => $model->id,
                'model_name' => $folderName,
                'file_original_name' => $file->getClientOriginalName(),
            ]);

            $systemFileName = $this->createSystemFileName($log, $file);
            $filePath = $this->createFilePath($folderName, $systemFileName);
            $folderPath = $this->createFilePath($folderName);

            Storage::put(
                $filePath,
                file_get_contents($file->path())
            );

            $log->fill([
                'file_path' => $filePath,
                'file_system_name' => $systemFileName
            ])->save();

            if ($width)
                $this->imageResize($width, $file, $filePath);

            $updatedFiles[] = [
                'file_log_id' => $log->id,
                'path' => asset($log->file_path),
                'file_original_name' => $log->file_original_name
            ];
        }

        $model->$fileAttrName = $updatedFiles;
        return $model;
    }
public function upload($model, $folderName, $files, $fileAttrName = 'files', $width = null)
    {
        $updatedFiles = $model->$fileAttrName;

        foreach ($files as $file) {

            $log = (new FileLog)->create([
                'model_id' => $model->id,
                'model_name' => $folderName,
                'file_original_name' => $file->getClientOriginalName(),
            ]);

            $systemFileName = $this->createSystemFileName($log, $file);
            $filePath = $this->createFilePath($folderName, $systemFileName);
            $folderPath = $this->createFilePath($folderName);

            Storage::put(
                $filePath,
                file_get_contents($file->path())
            );

            $log->fill([
                'file_path' => $filePath,
                'file_system_name' => $systemFileName
            ])->save();

            if ($width)
                $this->imageResize($width, $file, $filePath);

            $updatedFiles[] = [
                'file_log_id' => $log->id,
                'path' => asset($log->file_path),
                'file_original_name' => $log->file_original_name
            ];
        }

        $model->$fileAttrName = $updatedFiles;
        return $model;
    }
public function upload ( $ model , $ folderName , $ files , $ fileAttrName = 'files' , $ width = null ) { $ updatedFiles = $ model -> $ fileAttrName ; foreach ( $ files as $ file ) { $ log = ( new FileLog ) -> create ( [ 'model_id' => $ model -> id , 'model_name' => $ folderName , 'file_original_name' => $ file -> getClientOriginalName ( ) , ] ) ; $ systemFileName = $ this -> createSystemFileName ( $ log , $ file ) ; $ filePath = $ this -> createFilePath ( $ folderName , $ systemFileName ) ; $ folderPath = $ this -> createFilePath ( $ folderName ) ; Storage :: put ( $ filePath , file_get_contents ( $ file -> path ( ) ) ) ; $ log -> fill ( [ 'file_path' => $ filePath , 'file_system_name' => $ systemFileName ] ) -> save ( ) ; if ( $ width ) $ this -> imageResize ( $ width , $ file , $ filePath ) ; $ updatedFiles [ ] = [ 'file_log_id' => $ log -> id , 'path' => asset ( $ log -> file_path ) , 'file_original_name' => $ log -> file_original_name ] ; } $ model -> $ fileAttrName = $ updatedFiles ; return $ model ; }
Upload files for model, without save model
@param  Model $model      - with 'files' attribute
@param  string $folderName
@param  Files $files
@return Model
Upload files for model without save model