generated from liutk/owl-admin-base
61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
use App\Admin\Filters\AgreementFilter;
|
|
use App\Models\{Agreement, WorkflowCheck};
|
|
use Illuminate\Support\Facades\{Validator, Storage};
|
|
use Illuminate\Support\Str;
|
|
|
|
class AgreementService extends BaseService
|
|
{
|
|
protected array $withRelationships = ['employee', 'workflow'];
|
|
|
|
protected string $modelName = Agreement::class;
|
|
|
|
protected string $modelFilterName = AgreementFilter::class;
|
|
|
|
public function resloveData($data, $model = null)
|
|
{
|
|
if (isset($data['images']) && $data['images']) {
|
|
$images = [];
|
|
foreach ($data['images'] as $value) {
|
|
$image = data_get($value, 'value');
|
|
$url = Str::startsWith($image, ['http://', 'https://']) ? $image : Storage::url($image);
|
|
array_push($images, [
|
|
'value' => $image,
|
|
'preview' => $url,
|
|
]);
|
|
}
|
|
$data['images'] = $images;
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function validate($data, $model = null)
|
|
{
|
|
$createRules = [
|
|
'employee_id' => ['required'],
|
|
'name' => ['required'],
|
|
];
|
|
$updateRules = [];
|
|
$validator = Validator::make($data, $model ? $updateRules : $createRules);
|
|
if ($validator->fails()) {
|
|
return $validator->errors()->first();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function delete(string $ids): mixed
|
|
{
|
|
$id = explode(',', $ids);
|
|
|
|
foreach (Agreement::whereIn('id', $id)->get() as $item) {
|
|
$item->delete();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|