generated from liutk/owl-admin-base
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use App\Models\ProjectCate;
|
|
use App\Models\Filters\ProjectCateFilter;
|
|
use App\Traits\UploadTrait;
|
|
use Illuminate\Support\Arr;
|
|
|
|
/**
|
|
* @method ProjectCate getModel()
|
|
* @method ProjectCate|\Illuminate\Database\Query\Builder query()
|
|
*/
|
|
class ProjectCateService extends BaseService
|
|
{
|
|
use UploadTrait;
|
|
|
|
protected string $modelName = ProjectCate::class;
|
|
|
|
protected string $modelFilterName = ProjectCateFilter::class;
|
|
|
|
public function store($data): bool
|
|
{
|
|
$columns = $this->getTableColumns();
|
|
$model = $this->getModel();
|
|
|
|
$data['cover'] = $this->saveImage('cover', 'project_cates/cover')[0] ?? '';
|
|
|
|
foreach ($data as $k => $v) {
|
|
if (!in_array($k, $columns)) {
|
|
continue;
|
|
}
|
|
|
|
$model->setAttribute($k, $v);
|
|
}
|
|
|
|
return $model->save();
|
|
}
|
|
|
|
public function update($primaryKey, $data): bool
|
|
{
|
|
$columns = $this->getTableColumns();
|
|
$model = $this->query()->whereKey($primaryKey)->first();
|
|
|
|
|
|
if(isset($data['cover'])){
|
|
$data['cover'] = $this->saveImage('cover', 'project_cates/cover')[0] ?? '';
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
if (!in_array($k, $columns)) {
|
|
continue;
|
|
}
|
|
|
|
$model->setAttribute($k, $v);
|
|
}
|
|
|
|
return $model->save();
|
|
}
|
|
} |