Private Disk Added

This commit is contained in:
devansh bawari 2021-06-24 15:44:26 +05:30
parent 20cd22fd1b
commit da7cb3a16b
4 changed files with 26 additions and 8 deletions

View File

@ -48,6 +48,12 @@ return [
'root' => storage_path('app'), 'root' => storage_path('app'),
], ],
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'url' => env('APP_URL') . '/storage',
],
'public' => [ 'public' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app/public'), 'root' => storage_path('app/public'),

View File

@ -3,22 +3,24 @@
namespace Webkul\Product\Repositories; namespace Webkul\Product\Repositories;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Webkul\Core\Eloquent\Repository;
class ProductDownloadableLinkRepository extends Repository class ProductDownloadableLinkRepository extends Repository
{ {
/** /**
* Specify Model class name * Specify model class name.
* *
* @return string * @return string
*/ */
function model() public function model()
{ {
return 'Webkul\Product\Contracts\ProductDownloadableLink'; return 'Webkul\Product\Contracts\ProductDownloadableLink';
} }
/** /**
* Upload.
*
* @param array $data * @param array $data
* @param integer $productId * @param integer $productId
* @return array * @return array
@ -28,7 +30,7 @@ class ProductDownloadableLinkRepository extends Repository
foreach ($data as $type => $file) { foreach ($data as $type => $file) {
if (request()->hasFile($type)) { if (request()->hasFile($type)) {
return [ return [
$type => $path = request()->file($type)->store('product_downloadable_links/' . $productId), $type => $path = request()->file($type)->store('product_downloadable_links/' . $productId, 'private'),
$type . '_name' => $file->getClientOriginalName(), $type . '_name' => $file->getClientOriginalName(),
$type . '_url' => Storage::url($path), $type . '_url' => Storage::url($path),
]; ];
@ -39,8 +41,10 @@ class ProductDownloadableLinkRepository extends Repository
} }
/** /**
* Save links.
*
* @param array $data * @param array $data
* @param \Webkul\Product\Contracts\Product $product * @param \Webkul\Product\Models\Product $product
* @return void * @return void
*/ */
public function saveLinks(array $data, $product) public function saveLinks(array $data, $product)
@ -67,4 +71,4 @@ class ProductDownloadableLinkRepository extends Repository
$this->delete($linkId); $this->delete($linkId);
} }
} }
} }

View File

@ -89,7 +89,11 @@ class DownloadableProductController extends Controller
} }
if ($downloadableLinkPurchased->type == 'file') { if ($downloadableLinkPurchased->type == 'file') {
return Storage::download($downloadableLinkPurchased->file); $privateDisk = Storage::disk('private');
return $privateDisk->exists($downloadableLinkPurchased->file)
? $privateDisk->download($downloadableLinkPurchased->file)
: abort(404);
} else { } else {
$fileName = $name = substr($downloadableLinkPurchased->url, strrpos($downloadableLinkPurchased->url, '/') + 1);; $fileName = $name = substr($downloadableLinkPurchased->url, strrpos($downloadableLinkPurchased->url, '/') + 1);;

View File

@ -96,7 +96,11 @@ class ProductController extends Controller
$productDownloadableLink = $this->productDownloadableLinkRepository->findOrFail(request('id')); $productDownloadableLink = $this->productDownloadableLinkRepository->findOrFail(request('id'));
if ($productDownloadableLink->sample_type == 'file') { if ($productDownloadableLink->sample_type == 'file') {
return Storage::download($productDownloadableLink->sample_file); $privateDisk = Storage::disk('private');
return $privateDisk->exists($productDownloadableLink->sample_file)
? $privateDisk->download($productDownloadableLink->sample_file)
: abort(404);
} else { } else {
$fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1); $fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1);