changed media folder structure

This commit is contained in:
Denis Duliçi
2021-05-08 18:18:00 +03:00
parent 1fb81aa46e
commit 02391b766a
4 changed files with 144 additions and 72 deletions

View File

@ -3,13 +3,15 @@
namespace App\Http\Controllers\Common;
use App\Abstracts\Http\Controller;
use Illuminate\Http\Request;
use App\Models\Common\Media;
use App\Traits\Uploads as Helper;
use Illuminate\Http\Request;
use File;
use Storage;
class Uploads extends Controller
{
use Helper;
/**
* Get the specified resource.
*
@ -25,7 +27,7 @@ class Uploads extends Controller
}
// Get file path
if (!$path = $this->getPath($media)) {
if (!$path = $this->getMediaPathOnStorage($media)) {
return response(null, 204);
}
@ -68,7 +70,7 @@ class Uploads extends Controller
}
// Get file path
if (!$path = $this->getPath($media)) {
if (!$path = $this->getMediaPathOnStorage($media)) {
return response()->json([
'success' => false,
'error' => true,
@ -106,7 +108,7 @@ class Uploads extends Controller
}
// Get file path
if (!$path = $this->getPath($media)) {
if (!$path = $this->getMediaPathOnStorage($media)) {
return false;
}
@ -139,7 +141,7 @@ class Uploads extends Controller
}
// Get file path
if (!$path = $this->getPath($media)) {
if (!$path = $this->getMediaPathOnStorage($media)) {
$message = trans('messages.warning.deleted', ['name' => $media->basename, 'text' => $media->basename]);
flash($message)->warning()->important();
@ -163,38 +165,4 @@ class Uploads extends Controller
return $return;
}
/**
* Get the full path of resource.
*
* @param $media
* @return boolean|string
*/
protected function getPath($media)
{
if (!is_object($media)) {
return false;
}
$path = $media->basename;
if (!empty($media->directory)) {
$folders = explode('/', $media->directory);
// Check if company can access media
if ($folders[0] != company_id()) {
return false;
}
$path = $media->directory . '/' . $media->basename;
}
if (!Storage::exists($path)) {
return false;
}
$full_path = Storage::path($path);
return $full_path;
}
}