75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Botanic;
|
|
|
|
use App\Exports\Botanic\SpeciesExport;
|
|
use App\Models\Botanic\Specie;
|
|
use App\Repositories\Core\Tag;
|
|
use App\Traits\Model\Basic;
|
|
use App\Traits\Repository\Imageable;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class Species
|
|
{
|
|
use Basic, Imageable;
|
|
|
|
public static function getDescription($id)
|
|
{
|
|
return self::get($id)->description ?? '';
|
|
}
|
|
|
|
public static function getTags($id)
|
|
{
|
|
$model = self::get($id) ?? false;
|
|
|
|
return $model ? $model->tags->toArray() : false;
|
|
}
|
|
|
|
public static function getFull($id)
|
|
{
|
|
$specie = self::get($id);
|
|
$data = $specie->toArray();
|
|
$data['tags'] = self::getTagsBySpecie($specie);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public static function getTagsBySpecie($specie)
|
|
{
|
|
return Tag::getTagsByModel($specie);
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return Specie::with('tags.tag_group')->find($id);
|
|
}
|
|
|
|
public static function storeFull($data)
|
|
{
|
|
$images = $data['images'] ?? false;
|
|
$tags = $data['tags'] ?? false;
|
|
unset($data['images']);
|
|
unset($data['tags']);
|
|
$specie = self::store($data);
|
|
self::storeImages($specie, $images);
|
|
self::storeTags($specie, $tags);
|
|
|
|
return $specie;
|
|
}
|
|
|
|
public static function storeTags($specie, $tags)
|
|
{
|
|
return Tag::storeTags($specie, $tags);
|
|
}
|
|
|
|
public static function exportExcel()
|
|
{
|
|
return Excel::download(new SpeciesExport(), 'species.xlsx');
|
|
}
|
|
|
|
public static function getModel()
|
|
{
|
|
return Specie::query();
|
|
}
|
|
}
|