category qosishsh to'g'irlandi
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
namespace App\Http\Requests\Dashboard\Category;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Support\Uploads;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
|
||||
class Update extends FormRequest
|
||||
{
|
||||
@@ -52,12 +53,31 @@ class Update extends FormRequest
|
||||
{
|
||||
if ($this->hasFile('image')) {
|
||||
Storage::disk('local')->delete($category->image);
|
||||
return Uploads::store($this->file('image'), 'uploads/categories', 'local');
|
||||
return $this->storeCategoryImage($this->file('image'));
|
||||
}
|
||||
|
||||
return $category->image;
|
||||
}
|
||||
|
||||
private function storeCategoryImage(UploadedFile $file): string
|
||||
{
|
||||
$relativeDirectory = 'uploads/categories';
|
||||
$directory = public_path($relativeDirectory);
|
||||
|
||||
if (!is_dir($directory) && !mkdir($directory, 0775, true) && !is_dir($directory)) {
|
||||
throw new RuntimeException("Category upload directory could not be created: {$directory}");
|
||||
}
|
||||
|
||||
if (!is_writable($directory)) {
|
||||
throw new RuntimeException("Category upload directory is not writable: {$directory}");
|
||||
}
|
||||
|
||||
$fileName = $file->hashName();
|
||||
$file->move($directory, $fileName);
|
||||
|
||||
return "{$relativeDirectory}/{$fileName}";
|
||||
}
|
||||
|
||||
public function getFilterPower()
|
||||
{
|
||||
if ($this->get('is_filter_power') == 'true') {
|
||||
|
||||
Reference in New Issue
Block a user