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

@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Storage;
* File property
* @property string $name
* @property string $description
* @property string $disk
* @property string $path
* @property boolean $public
* @package App\Models
@@ -24,6 +25,7 @@ class File extends Model
protected $fillable = [
'name',
'description',
'disk',
'path',
'public',
'ref_model',
@@ -40,14 +42,16 @@ class File extends Model
*/
public function getUrlAttribute(): string
{
$disk = config('filesystems.public_files');
$disk = $this->disk ?? config('filesystems.public_files');
// If the disk isn't stored in public (S3 or something),
// just pass through the URL call
if ($disk !== 'public') {
return Storage::disk(config('filesystems.public_files'))
->url($this->path);
}
return public_asset(Storage::disk('public')
->url($this->path)
);
// Otherwise, figure out the public URL and save there
return public_asset(Storage::disk('public')->url($this->path));
}
}