From f7efac363e663c97de3b5bb1f4bde5c9cdd06743 Mon Sep 17 00:00:00 2001 From: Sashagm Date: Thu, 29 Jun 2023 23:38:43 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- src/Http/Controllers/ThemesController.php | 4 +- src/Models/Themes.php | 9 ++- src/Traits/ThemesTrait.php | 68 +++++++++-------------- 4 files changed, 36 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 6a6bb3e..898c919 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,10 @@ if (Themes){ require __DIR__ ."/". Themes .".php"; } 'check' => [ - 'active' => true, // разрешить проверку или false пропускать + 'active' => true, // True Разрешить проверку или false Пропускать проверку - 'save_colum' => 'id', // поле для группы/роли или прав - 'save_value' => 1, // какое значение необходимо получить + 'save_colum' => 'id', // Поле для группы/роли или прав + 'save_value' => 1, // Какое значение необходимо получить ], diff --git a/src/Http/Controllers/ThemesController.php b/src/Http/Controllers/ThemesController.php index 8a24b0e..0a82b44 100644 --- a/src/Http/Controllers/ThemesController.php +++ b/src/Http/Controllers/ThemesController.php @@ -44,8 +44,6 @@ public function getThemes() public function addThemes(Request $request) { - $this->checkAccess(); - $this->create($request); return back() @@ -56,7 +54,7 @@ public function addThemes(Request $request) public function deleteThemes(Request $request, $id) { - $this->checkAccess(); + if ($id == 1) { return back() ->with('success', "Тему с ид: $id нельзя удалить так как она резервная и системная!"); diff --git a/src/Models/Themes.php b/src/Models/Themes.php index c85675e..fe2d4b9 100644 --- a/src/Models/Themes.php +++ b/src/Models/Themes.php @@ -22,21 +22,24 @@ class Themes extends Model public static function getActiveThemeTitle() { - $theme = self::where('active', 1)->first(); + $theme = self::where('active', 1) + ->first(); return $theme->title ?? null; } public static function getActiveThemeDescription() { - $theme = self::where('active', 1)->first(); + $theme = self::where('active', 1) + ->first(); return $theme->description ?? null; } public static function getThemeInfo() { - $theme = self::where('active', 1)->first(); + $theme = self::where('active', 1) + ->first(); return [ 'title' => $theme->title ?? null, diff --git a/src/Traits/ThemesTrait.php b/src/Traits/ThemesTrait.php index 0f51a44..7aacce4 100644 --- a/src/Traits/ThemesTrait.php +++ b/src/Traits/ThemesTrait.php @@ -17,27 +17,30 @@ trait ThemesTrait private function save($id) { $info = Themes::findOrFail($id); - + if (!$info) { throw new Exception('Тема не найдена'); } - + DB::beginTransaction(); - + try { - DB::table('themes')->update(['active' => 0]); - DB::table('themes')->where('id', $id)->update(['active' => 1]); - + DB::table('themes') + ->update(['active' => 0]); + DB::table('themes') + ->where('id', $id) + ->update(['active' => 1]); + $data = "title'); } \r\n"; - - $new_file=fopen( __DIR__ . '/../../../../../config/themes.php',"w"); + + $new_file = fopen(__DIR__ . '/../../../../../config/themes.php', "w"); fwrite($new_file, $data); fclose($new_file); - + DB::commit(); } catch (\Exception $e) { DB::rollback(); @@ -47,10 +50,10 @@ private function save($id) private function clear() { - Artisan::call('cache:clear'); - Artisan::call('config:cache'); - Artisan::call('view:clear'); - Artisan::call('route:clear'); + Artisan::call('cache:clear'); + Artisan::call('config:cache'); + Artisan::call('view:clear'); + Artisan::call('route:clear'); } @@ -58,7 +61,7 @@ private function clear() private function getCurrent() { $info = Themes::where('title', Themes) - ->get(); + ->get(); if (!$info) { throw new Exception('Тема не найдена'); @@ -77,35 +80,16 @@ private function getCurrent() - private function checkAccess() { - switch(false) { - case true: - $user = Auth::user(); - if (!$user){ - abort(403); // отправляем ошибку 403 Forbidden - } - if($user->id === 1) { // проверяем роль пользователя - return true; - } else { - abort(403); // отправляем ошибку 403 Forbidden - } - case false: - return true; - } - } - private function create(Request $request) { - Themes::query()->create([ - 'title' => $request->title, - 'description' => $request->desc, - 'author' => $request->author, - 'version' => $request->ver, - 'active' => 0, - ]); - + Themes::query() + ->create([ + 'title' => $request->title, + 'description' => $request->desc, + 'author' => $request->author, + 'version' => $request->ver, + 'active' => 0, + ]); } - - }