[WIP] Working on uploader
This commit is contained in:
@@ -19,11 +19,7 @@ class ArticleFamiliesDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
->width(120)
|
||||
->addClass('text-center'),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ class TagGroupsDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('tags_count')->title('Nb de tags')->searchable(false)->addClass('text-right'),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -12,13 +12,16 @@ class TagsDataTable extends DataTable
|
||||
|
||||
public function query(Tag $model)
|
||||
{
|
||||
$model = $model::with('group')->select(['tagging_tags.*']);
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('group.name')->title('Groupe'),
|
||||
Column::make('order')->title('Ordre'),
|
||||
Column::make('name')->title('Nom'),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Shop\TagGroups;
|
||||
use App\DataTables\Botanic\VarietiesDataTable;
|
||||
|
||||
use App\Models\Shop\Variety;
|
||||
@@ -30,25 +31,32 @@ class VarietyController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('Botanic.Admin.Varieties.create');
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Botanic.Admin.Varieties.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Varieties::store($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);
|
||||
return redirect()->route('Botanic.Admin.Varieties.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data = Varieties::get($id);
|
||||
return view('Botanic.Admin.Varieties.view', $data);
|
||||
return view('Botanic.Admin.Varieties.view', Varieties::get($id));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Varieties::get($id);
|
||||
$data = Varieties::getWithImages($id)->toArray();
|
||||
$data['species'] = Species::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Botanic.Admin.Varieties.edit', $data);
|
||||
}
|
||||
|
||||
@@ -57,4 +65,9 @@ class VarietyController extends Controller
|
||||
return Varieties::destroy($id);
|
||||
}
|
||||
|
||||
public function deleteImage($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\ArticleAttributeFamilies;
|
||||
use App\Repositories\Shop\ArticleFamilies;
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\Repositories\Shop\TagGroups;
|
||||
use App\DataTables\Shop\ArticlesDataTable;
|
||||
|
||||
class ArticleController extends Controller
|
||||
@@ -29,6 +30,7 @@ class ArticleController extends Controller
|
||||
$data['categories'] = Categories::getOptions();
|
||||
$data['families'] = ArticleFamilies::getOptions();
|
||||
$data['attribute_families'] = ArticleAttributeFamilies::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
return view('Shop.Admin.Articles.create', $data);
|
||||
}
|
||||
@@ -49,6 +51,10 @@ class ArticleController extends Controller
|
||||
{
|
||||
$data = Articles::get($id);
|
||||
$data['categories'] = Articles::getOptions();
|
||||
$data['families'] = ArticleFamilies::getOptions();
|
||||
$data['attribute_families'] = ArticleAttributeFamilies::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
return view('Shop.Admin.Articles.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ class CategoryController extends Controller
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
$data['category_id'] = 0;
|
||||
$data['categories'] = Categories::getOptions();
|
||||
return view('Shop.Admin.Categories.create', $data);
|
||||
}
|
||||
@@ -42,7 +43,7 @@ class CategoryController extends Controller
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Categories::get($id);
|
||||
$data = Categories::get($id)->toArray();
|
||||
$data['categories'] = Categories::getOptions();
|
||||
return view('Shop.Admin.Categories.edit', $data);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
namespace App\Models\Botanic;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\MediaLibrary\HasMedia\HasMedia;
|
||||
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
|
||||
|
||||
class Variety extends Model
|
||||
class Variety extends Model implements HasMedia
|
||||
{
|
||||
use HasMediaTrait;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'botanic_varieties';
|
||||
|
||||
@@ -13,4 +17,9 @@ class Variety extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Botanic\Specie');
|
||||
}
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Article','id','model_id');
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Spatie\MediaLibrary\HasMedia\HasMedia;
|
||||
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Conner\Tagging\Taggable;
|
||||
|
||||
@@ -11,6 +12,7 @@ class Article extends Model
|
||||
{
|
||||
use Categorizable;
|
||||
use Taggable;
|
||||
use HasMediaTrait;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_articles';
|
||||
|
||||
@@ -9,10 +9,9 @@ class Tag extends Model
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'tagging_tags';
|
||||
|
||||
|
||||
public function group()
|
||||
{
|
||||
return $this->hasOne('App\Models\Shop\TagGroup');
|
||||
return $this->hasOne('App\Models\Shop\TagGroup','id','tag_group_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,11 +45,20 @@ class Varieties
|
||||
return Variety::find($id);
|
||||
}
|
||||
|
||||
public static function getWithImages($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$variety->getMedia();
|
||||
// $variety = $variety->toArray();
|
||||
foreach ($variety->media as $key => $media) {
|
||||
$variety->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $variety;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
return isset($data['id']) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -59,7 +68,9 @@ class Varieties
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Variety::find($id)->update($data);
|
||||
$variety = self::get($data['id']);
|
||||
$variety->update($data);
|
||||
return $variety;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
@@ -67,4 +78,13 @@ class Varieties
|
||||
return Variety::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeImages($variety, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
$variety->addMedia($file)->toMediaCollection('images');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,25 +8,25 @@ use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\ArticleComponent;
|
||||
|
||||
class Articles
|
||||
class ArticleComponents
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Article::orderBy('name');
|
||||
$model = ArticleComponent::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Article::orderBy('name','asc')->get();
|
||||
return ArticleComponent::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Article::find($id);
|
||||
return ArticleComponent::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
@@ -38,17 +38,17 @@ class Articles
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Article::create($data);
|
||||
return ArticleComponent::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Article::find($id)->update($data);
|
||||
return ArticleComponent::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Article::destroy($id);
|
||||
return ArticleComponent::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\TagGroup;
|
||||
@@ -24,6 +20,23 @@ class TagGroups
|
||||
return TagGroup::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTreeTags()
|
||||
{
|
||||
$items = TagGroup::with('tags')->get();
|
||||
$tags = [];
|
||||
foreach ($items as $group) {
|
||||
$group_tags = [];
|
||||
foreach ($group->tags as $tag) {
|
||||
$group_tags[$tag->id] = $tag->name;
|
||||
}
|
||||
$tags[] = [
|
||||
'label' => $group->name,
|
||||
'options' => $group_tags,
|
||||
];
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return TagGroup::orderBy('name','asc')->get();
|
||||
|
||||
@@ -8,25 +8,30 @@ use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\TagGroup;
|
||||
use App\Models\Shop\Tag;
|
||||
|
||||
class TagGroups
|
||||
class Tags
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = TagGroup::orderBy('name');
|
||||
$model = Tag::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tag::get()->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return TagGroup::orderBy('name','asc')->get();
|
||||
return Tag::orderBy('order','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return TagGroup::find($id);
|
||||
return Tag::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
@@ -38,17 +43,17 @@ class TagGroups
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return TagGroup::create($data);
|
||||
return Tag::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return TagGroup::find($id)->update($data);
|
||||
return Tag::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return TagGroup::destroy($id);
|
||||
return Tag::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user