69 lines
1.4 KiB
PHP
69 lines
1.4 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 Maatwebsite\Excel\Facades\Excel;
|
|
|
|
use App\Models\Botanic\Specie;
|
|
use App\Exports\Botanic\SpeciesExport;
|
|
|
|
class Species
|
|
{
|
|
|
|
public static function getDatatable()
|
|
{
|
|
$model = Specie::orderBy('name');
|
|
return Datatables::of($model)->make(true);
|
|
}
|
|
|
|
public static function getOptions()
|
|
{
|
|
return Specie::get()->SortBy('name')->pluck('name','id')->toArray();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return Specie::orderBy('name','asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return Specie::find($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$item = $id ? self::update($data, $id) : self::create($data);
|
|
return $item->id;
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return Specie::create($data);
|
|
}
|
|
|
|
public static function update($data, $id = false)
|
|
{
|
|
$id = $id ? $id : $data['id'];
|
|
$model = self::get($id);
|
|
$ret = $model->update($data);
|
|
return $model;
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return Specie::destroy($id);
|
|
}
|
|
|
|
public static function exportExcel()
|
|
{
|
|
return Excel::download(new SpeciesExport, 'species.xlsx');
|
|
}
|
|
}
|