71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Botanic;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
use Yajra\DataTables\DataTables;
|
|
|
|
use App\Models\Botanic\Variety;
|
|
|
|
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();
|
|
}
|
|
|
|
public static function getOptionsWithSpecie()
|
|
{
|
|
$varieties = Variety::with('specie')->get();
|
|
$data = [];
|
|
foreach ($varieties as $variety)
|
|
{
|
|
$data[] = ['id' => $variety->id, 'text' => (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name];
|
|
}
|
|
return collect($data)->sortBy('text')->values()->all();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return Variety::orderBy('name','asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return Variety::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 Variety::create($data);
|
|
}
|
|
|
|
public static function update($data)
|
|
{
|
|
return Variety::find($id)->update($data);
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return Variety::destroy($id);
|
|
}
|
|
|
|
}
|