75 lines
1.5 KiB
PHP
75 lines
1.5 KiB
PHP
<?php
|
|
|
|
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\Article;
|
|
|
|
class Articles
|
|
{
|
|
|
|
public static function getDatatable()
|
|
{
|
|
$model = Article::orderBy('name');
|
|
return Datatables::of($model)->make(true);
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return Article::orderBy('name','asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return Article::find($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$item = $id ? self::update($data) : self::create($data);
|
|
return $item->id;
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return Article::create($data);
|
|
}
|
|
|
|
public static function update($data)
|
|
{
|
|
return Article::find($id)->update($data);
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return Article::destroy($id);
|
|
}
|
|
|
|
public static function getImages($id)
|
|
{
|
|
$variety = self::get($id);
|
|
$variety->getMedia();
|
|
foreach ($variety->media as $key => $media) {
|
|
$variety->media[$key]['url'] = $media->getUrl();
|
|
}
|
|
return $variety->media;
|
|
}
|
|
|
|
|
|
public static function deleteImage($id, $index)
|
|
{
|
|
$article = self::get($id);
|
|
$article->getMedia();
|
|
$ret = $article->media[$index]->delete();
|
|
return "1";
|
|
}
|
|
|
|
|
|
}
|