Fixes to file uploading; include disk name, remove clunky redirect code

This commit is contained in:
Nabeel Shahzad
2018-04-02 11:04:32 -05:00
parent 6c516cf4bf
commit 026a83591d
10 changed files with 97 additions and 90 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Services;
use App\Interfaces\Service;
/**
* Class FileService
* @package App\Services
*/
class FileService extends Service
{
/**
* Save a file to disk and return the path
* @param \Illuminate\Http\UploadedFile $file
* @param string $folder
* @param string|null $disk
* @return string
*/
public function saveFile($file, $folder, $disk = null): string
{
if (!$disk) {
$disk = config('filesystems.public_files');
}
$path_info = pathinfo($file->getClientOriginalName());
$filename = str_slug($path_info['filename']).'.'.$path_info['extension'];
return $file->storeAs($folder, $filename, $disk);
}
}