PATH:
home
/
rwabteecom
/
project_11
/
app
/
Services
/
Theme
/
Editing: ThemeServices.php
<?php namespace App\Services\Theme; use App\Helpers\Image; use App\Interfaces\ServiceInterface; use App\Models\Invoice; use App\Models\Theme; use App\Models\UserTheme; use App\Services\User\UserServices; use Carbon\Carbon; use DB; use Exception; use Illuminate\Support\Collection; class ThemeServices implements ServiceInterface { public function index($active = false): Collection { if ($active) { return Theme::query()->active()->get(); } return Theme::query()->get(); } public function findOrFail($id, $active = false): Theme { if ($active) { return Theme::query()->active()->findOrFail($id); } return Theme::query()->findOrFail($id); } public function findWithoutFail($id, $active = false): Theme|null { if ($active) { return Theme::query()->active()->find($id); } return Theme::query()->find($id); } public function store($request): void { DB::transaction(function () use ($request) { $theme = Theme::query()->create([ "title" => $request->title, ]); Image::updateImage($theme, $request->file("image"), 'image'); installTheme($theme->id, $request->file("file")); }); } public function update($id, $request): void { DB::transaction(function () use ($request, $id) { $theme = $this->findOrFail($id); $theme->update([ "title" => $request->title, ]); Image::updateImage($theme, $request->file("image"), 'image'); if($request->hasFile("file")){ installTheme($theme->id, $request->file("file")); } }); } public function destroy($id): void { DB::transaction(function () use ($id) { $theme = $this->findOrFail($id); if ($theme->is_free_theme) { throw new Exception(__("You can't delete free theme, you can disable it instead")); } $theme->delete(); }); } }
SAVE
CANCEL