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);
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
</div>
|
||||
|
||||
{{ Form::label('tags', 'Tags') }}
|
||||
@include('components.select-tree', ['name' => 'tags', 'list' => $tags_list, 'value' => isset($tags) ? $tags : null, 'class' => 'select2 form-control', 'multiple' => true])
|
||||
@include('components.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => isset($tags) ? $tags : null, 'class' => 'select2 form-control', 'multiple' => true])
|
||||
|
||||
|
||||
{{ Form::label('description', 'Description') }}
|
||||
@include('components.textarea', ['name' => 'description', 'value' => isset($description) ? $description : null, 'class' => 'editor', 'rows' => 5, 'required' => false])
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<div class="col row-image"></div>
|
||||
TEST
|
||||
<button type="button" class="btn btn-danger delete-image-btn"><i class="fa fa-minus-circle"></i></button>
|
||||
|
||||
<div class="thumbnail">
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@include('boilerplate::load.fileinput')
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Photos</h3>
|
||||
|
||||
Reference in New Issue
Block a user