Fix tags on varieties
This commit is contained in:
@@ -38,12 +38,7 @@ class VarietyController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
// dump($images);
|
||||
// exit;
|
||||
unset($data['images']);
|
||||
$variety = Varieties::store($data);
|
||||
Varieties::storeImages($variety, $images);
|
||||
Varieties::storeFull($data);
|
||||
return redirect()->route('Botanic.Admin.Varieties.index');
|
||||
}
|
||||
|
||||
@@ -54,7 +49,7 @@ class VarietyController extends Controller
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Varieties::get($id)->toArray();
|
||||
$data = Varieties::getFull($id);
|
||||
$data['species'] = Species::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Botanic.Admin.Varieties.edit', $data);
|
||||
|
||||
@@ -28,10 +28,7 @@ class ArticleController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
// dump($data);
|
||||
// exit;
|
||||
Articles::storeFull($data);
|
||||
Articles::storeFull($request->all());
|
||||
return redirect()->route('Shop.Admin.Articles.index');
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,33 @@ class Varieties
|
||||
return Variety::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$data = $variety->toArray();
|
||||
$data['tags'] = self::getTagsByVariety($variety);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getTagsByVariety($variety)
|
||||
{
|
||||
return $variety->tags->pluck('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']);
|
||||
$variety = self::store($data);
|
||||
self::storeImages($variety, $images);
|
||||
self::storeTags($variety, $tags);
|
||||
return $variety;
|
||||
}
|
||||
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return isset($data['id']) ? self::update($data) : self::create($data);
|
||||
@@ -55,10 +82,11 @@ class Varieties
|
||||
return Variety::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$variety = self::get($data['id']);
|
||||
$variety->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$variety = Variety::find($id);
|
||||
$ret = $variety->update($data);
|
||||
return $variety;
|
||||
}
|
||||
|
||||
@@ -67,6 +95,16 @@ class Varieties
|
||||
return Variety::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeTags($variety, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $variety->syncTags($tags, true);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static function storeImages($variety, $files)
|
||||
{
|
||||
if ($files) {
|
||||
|
||||
@@ -26,7 +26,7 @@ class Articles
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Articles::get($id);
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
|
||||
Reference in New Issue
Block a user