2020-01-16 07:52:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Velocity\Helpers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Webkul\Category\Repositories\CategoryRepository;
|
|
|
|
|
|
|
|
|
|
class AdminHelper
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* CategoryRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var object
|
|
|
|
|
*/
|
|
|
|
|
protected $categoryRepository;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
CategoryRepository $categoryRepository
|
|
|
|
|
) {
|
|
|
|
|
$this->categoryRepository = $categoryRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveLocaleImg($locale)
|
|
|
|
|
{
|
2020-01-20 10:44:02 +00:00
|
|
|
$uploadedImagePath = $this->uploadImage($locale, 'locale_image.image_0');
|
2020-01-16 07:52:18 +00:00
|
|
|
|
|
|
|
|
if ($uploadedImagePath) {
|
|
|
|
|
$locale->locale_image = $uploadedImagePath;
|
|
|
|
|
$locale->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $locale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeCategoryIcon($categoryId)
|
|
|
|
|
{
|
|
|
|
|
$category = $this->categoryRepository->findOrFail($categoryId);
|
|
|
|
|
|
2020-01-20 10:44:02 +00:00
|
|
|
$uploadedImagePath = $this->uploadImage($category, 'category_icon_path.image_1');
|
2020-01-16 07:52:18 +00:00
|
|
|
|
|
|
|
|
if ($uploadedImagePath) {
|
|
|
|
|
$category->category_icon_path = $uploadedImagePath;
|
|
|
|
|
$category->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $category;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 10:44:02 +00:00
|
|
|
public function uploadImage($record, $type)
|
2020-01-16 07:52:18 +00:00
|
|
|
{
|
|
|
|
|
$request = request();
|
|
|
|
|
|
|
|
|
|
$image = '';
|
|
|
|
|
$file = $type;
|
2020-01-20 10:44:02 +00:00
|
|
|
$dir = 'velocity/' . $type;
|
2020-01-16 07:52:18 +00:00
|
|
|
|
|
|
|
|
if ($request->hasFile($file)) {
|
2020-01-20 10:44:02 +00:00
|
|
|
if ($type == 'locale_image.image_0' && $record->locale_image) {
|
|
|
|
|
Storage::delete($record->locale_image);
|
|
|
|
|
}
|
|
|
|
|
if ($type == 'category_icon_path.image_1' && $record->category_icon_path) {
|
|
|
|
|
Storage::delete($record->category_icon_path);
|
|
|
|
|
}
|
2020-01-16 07:52:18 +00:00
|
|
|
|
|
|
|
|
$image = $request->file($file)->store($dir);
|
|
|
|
|
|
|
|
|
|
return $image;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeSliderDetails($slider)
|
|
|
|
|
{
|
|
|
|
|
$slider->slider_path = request()->get('slider_path');
|
|
|
|
|
$slider->save();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|