generated from liutk/owl-admin-base
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services\Train;
|
|
|
|
use App\Admin\Filters\TrianBookFilter;
|
|
use App\Admin\Services\BaseService;
|
|
use App\Models\Train\Book;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Str;
|
|
|
|
class BookService extends BaseService
|
|
{
|
|
protected array $withRelationships = ['category'];
|
|
|
|
protected string $modelName = Book::class;
|
|
|
|
protected string $modelFilterName = TrianBookFilter::class;
|
|
|
|
protected function formatUrl($str)
|
|
{
|
|
return Str::startsWith($str, ['http://', 'https://']) ? $str : Storage::url($str);
|
|
}
|
|
|
|
public function validate($data, $model = null)
|
|
{
|
|
$createRules = [
|
|
'title' => ['required'],
|
|
'category_id' => ['required'],
|
|
'type' => ['required'],
|
|
'files' => ['nullable', 'array'],
|
|
];
|
|
$updateRules = [
|
|
'files' => ['nullable', 'array'],
|
|
];
|
|
$validator = Validator::make($data, $model ? $updateRules : $createRules);
|
|
if ($validator->fails()) {
|
|
return $validator->errors()->first();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|