Add preview from father, add new features
This commit is contained in:
@@ -2,25 +2,18 @@
|
||||
|
||||
namespace App\Repositories\Botanic;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Media;
|
||||
use App\Models\Botanic\Variety;
|
||||
use App\Exports\Botanic\VarietiesExport;
|
||||
|
||||
class Varieties
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Variety::with('specie');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Variety::orderBy('name')->get()->pluck('name','id')->toArray();
|
||||
@@ -30,8 +23,7 @@ class Varieties
|
||||
{
|
||||
$varieties = Variety::with('specie')->get();
|
||||
$data = [];
|
||||
foreach ($varieties as $variety)
|
||||
{
|
||||
foreach ($varieties as $variety) {
|
||||
$data[$variety->id] = (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name;
|
||||
}
|
||||
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
@@ -45,7 +37,7 @@ class Varieties
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variety::find($id);
|
||||
return Variety::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
@@ -58,8 +50,7 @@ class Varieties
|
||||
|
||||
public static function getTagsByVariety($variety)
|
||||
{
|
||||
$tags = $variety->tags;
|
||||
return $tags ? $tags->pluck('id')->toArray() : null;
|
||||
return Tag::getTagsByModel($variety);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +80,7 @@ class Varieties
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$variety = Variety::find($id);
|
||||
$variety = self::get($id);
|
||||
$ret = $variety->update($data);
|
||||
return $variety;
|
||||
}
|
||||
@@ -101,43 +92,22 @@ class Varieties
|
||||
|
||||
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;
|
||||
return Tag::storeTags($variety, $tags);
|
||||
}
|
||||
|
||||
public static function storeImages($variety, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
$variety->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
}
|
||||
}
|
||||
return Media::storeImages($variety, $files);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
if ($variety) {
|
||||
$variety->getMedia();
|
||||
foreach ($variety->media as $key => $media) {
|
||||
$variety->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $variety->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$variety->getMedia();
|
||||
$ret = $variety->media[$index]->delete();
|
||||
return "1";
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
|
||||
Reference in New Issue
Block a user