Fixes on categories
This commit is contained in:
@@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Shop\Admin;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
|
|
||||||
use App\Repositories\Shop\CategoryProducts;
|
|
||||||
|
|
||||||
class CategoryProductController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for creating a new resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param \App\CategoryProduct $categoryProduct
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(CategoryProduct $categoryProduct)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for editing the specified resource.
|
|
||||||
*
|
|
||||||
* @param \App\CategoryProduct $categoryProduct
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function edit(CategoryProduct $categoryProduct)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \App\CategoryProduct $categoryProduct
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(Request $request, CategoryProduct $categoryProduct)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\CategoryProduct $categoryProduct
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(CategoryProduct $categoryProduct)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -57,4 +57,19 @@ class CategoryController extends Controller
|
|||||||
{
|
{
|
||||||
return Categories::destroy($id);
|
return Categories::destroy($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getImages(Request $request, $id = false)
|
||||||
|
{
|
||||||
|
$id = $id ? $id : $request->input('id');
|
||||||
|
$data['images'] = Categories::getImages($id);
|
||||||
|
return view('components.uploader.mini-gallery-items', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteImage(Request $request)
|
||||||
|
{
|
||||||
|
$id = $request->input('id');
|
||||||
|
$index = $request->input('index');
|
||||||
|
return Categories::deleteImage($id, $index);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,18 @@
|
|||||||
namespace App\Models\Shop;
|
namespace App\Models\Shop;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Spatie\MediaLibrary\HasMedia\HasMedia;
|
||||||
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
|
||||||
use Rinvex\Categories\Traits\Categorizable;
|
use Rinvex\Categories\Traits\Categorizable;
|
||||||
|
use Rinvex\Tags\Traits\Taggable;
|
||||||
// use Conner\Tagging\Taggable;
|
// use Conner\Tagging\Taggable;
|
||||||
|
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
|
||||||
|
|
||||||
class Category extends Model
|
class Category extends Model
|
||||||
{
|
{
|
||||||
|
use Taggable;
|
||||||
|
use HasMediaTrait;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
protected $table = 'shop_categories';
|
protected $table = 'shop_categories';
|
||||||
|
|
||||||
|
|||||||
@@ -35,12 +35,70 @@ class Categories
|
|||||||
return Category::get()->pluck('name','category_id')->toArray();
|
return Category::get()->pluck('name','category_id')->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function storeFull($data)
|
||||||
|
{
|
||||||
|
$images = isset($data['images']) ? $data['images'] : false;
|
||||||
|
// $tags = isset($data['tags']) ? $data['tags'] : false;
|
||||||
|
unset($data['images']);
|
||||||
|
// unset($data['tags']);
|
||||||
|
$category = self::store($data);
|
||||||
|
self::storeImages($category, $images);
|
||||||
|
// self::storeTags($category, $tags);
|
||||||
|
return $category;
|
||||||
|
}
|
||||||
|
|
||||||
public static function store($data)
|
public static function store($data)
|
||||||
{
|
{
|
||||||
$id = isset($data['id']) ? $data['id'] : false;
|
$id = isset($data['id']) ? $data['id'] : false;
|
||||||
return $id ? self::update($data, $id) : self::create($data);
|
return $id ? self::update($data, $id) : self::create($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function storeTags($category, $tags)
|
||||||
|
{
|
||||||
|
if ($tags) {
|
||||||
|
$tags = collect($tags)->transform(function ($item, $key) {
|
||||||
|
return (int) $item;
|
||||||
|
})->toArray();
|
||||||
|
return $category->syncTags($tags, true);
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function storeImages($category, $files)
|
||||||
|
{
|
||||||
|
if ($files) {
|
||||||
|
foreach ($files as $file) {
|
||||||
|
self::storeImage($category, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function storeImage($category, $file)
|
||||||
|
{
|
||||||
|
return $article->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getImages($id)
|
||||||
|
{
|
||||||
|
$category = self::get($id);
|
||||||
|
if ($category) {
|
||||||
|
$category->getMedia();
|
||||||
|
foreach ($category->media as $key => $media) {
|
||||||
|
$category->media[$key]['url'] = $media->getUrl();
|
||||||
|
}
|
||||||
|
return $category->media;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteImage($id, $index)
|
||||||
|
{
|
||||||
|
$category = self::get($id);
|
||||||
|
$category->getMedia();
|
||||||
|
$ret = $category->media[$index]->delete();
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
|
||||||
public static function create($data)
|
public static function create($data)
|
||||||
{
|
{
|
||||||
$node = CategoryTrees::create($data);
|
$node = CategoryTrees::create($data);
|
||||||
@@ -52,7 +110,8 @@ class Categories
|
|||||||
public static function update($data, $id = false)
|
public static function update($data, $id = false)
|
||||||
{
|
{
|
||||||
$id = $id ? $id : $data['id'];
|
$id = $id ? $id : $data['id'];
|
||||||
$category = Category::find($id)->update($data);
|
$category = Category::find($id);
|
||||||
|
$ret = $category->update($data);
|
||||||
CategoryTrees::update($data, $category->category_id);
|
CategoryTrees::update($data, $category->category_id);
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
@@ -66,7 +125,7 @@ class Categories
|
|||||||
|
|
||||||
public static function getRoot()
|
public static function getRoot()
|
||||||
{
|
{
|
||||||
return app('rinvex.categorys.category')->find(1);
|
return app('rinvex.categories.category')->find(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{{ Form::label('photo', 'Photos') }}
|
{{ Form::label('photo', 'Photos') }}
|
||||||
@include('components.file', ['name' => 'photo', 'value' => isset($photo) ? $photo : null, 'required' => true])
|
@include('components.uploader.widget', ['load_url' => route('Shop.Admin.Categories.getImages', ['id' => (isset($id)) ? $id : false]), 'delete_url' => route('Shop.Admin.Categories.deleteImage') ])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,8 @@ Route::prefix('Categories')->name('Categories.')->group(function () {
|
|||||||
Route::post('store', 'CategoryController@store')->name('store');
|
Route::post('store', 'CategoryController@store')->name('store');
|
||||||
Route::get('edit/{id}', 'CategoryController@edit')->name('edit');
|
Route::get('edit/{id}', 'CategoryController@edit')->name('edit');
|
||||||
|
|
||||||
|
Route::any('getImages/{id?}', 'CategoryController@getImages')->name('getImages');
|
||||||
|
Route::post('deleteImage', 'CategoryController@deleteImage')->name('deleteImage');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user