diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index c2801a1..d7cedae 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -816,25 +816,48 @@ function getGroupBySetting($key) } /** - * get group by setting key + * get menu by setting key * @param $key * @return Menu */ function getMenuBySetting($key) { + if (Menu::count() == 0) { + return []; + } return Menu::where('id', getSetting($key) ?? 1)->first(); } +/** + * get menu's items by setting key + * @param $key + * @return array + */ +function getMenuBySettingItems($key) +{ + if (Menu::count() == 0) { + return []; + } + $r = Menu::where('id', getSetting($key) ?? 1)->first(); + if ($r == null) { + $r = Menu::first(); + } + return $r->items; +} + /** * get group's posts by setting key * @param $key * @param integer $limit - * @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C + * @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C|array */ function getGroupPostsBySetting($key, $limit = 10, $order = 'id', $dir = "DESC") { - return Group::where('id', getSetting($key) ?? 1)->first() - ->posts()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get(); + $g = Group::where('id', getSetting($key) ?? 1)->first(); + if ($g == null) { + return []; + } + return $g->posts()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get(); } /** @@ -857,12 +880,15 @@ function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "D * @param integer $limit * @param string $order * @param string $dir - * @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C + * @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C | array */ function getCategorySubCatsBySetting($key, $limit = 10, $order = 'id', $dir = "DESC") { - return Category::where('id', getSetting($key) ?? 1)->first() - ->children()->orderBy($order, $dir)->limit($limit)->get(); + $c = Category::where('id', getSetting($key) ?? 1)->first(); + if ($c == null) { + return []; + } + return $c->children()->orderBy($order, $dir)->limit($limit)->get(); } /** @@ -994,6 +1020,7 @@ function postsUrl() { return fixUrlLang(\route('client.posts')); } + /** * products url to best experience for multi lang shops * @return string @@ -1002,6 +1029,7 @@ function productsUrl() { return fixUrlLang(\route('client.products')); } + /** * clips url to best experience for multi lang shops * @return string @@ -1010,6 +1038,7 @@ function clipsUrl() { return fixUrlLang(\route('client.clips')); } + /** * galleries url to best experience for multi lang shops * @return string @@ -1018,6 +1047,7 @@ function gallariesUrl() { return fixUrlLang(\route('client.galleries')); } + /** * attachments url to best experience for multi lang shops * @return string @@ -1101,11 +1131,11 @@ function transports() */ function defTrannsport() { - if (\App\Models\Transport::where('is_default',1)->count() == 0){ + if (\App\Models\Transport::where('is_default', 1)->count() == 0) { return null; } - return \App\Models\Transport::where('is_default',1)->first()->id; + return \App\Models\Transport::where('is_default', 1)->first()->id; } @@ -1114,7 +1144,8 @@ function defTrannsport() * @param $array * @return false|string */ -function vueTranslate($array){ +function vueTranslate($array) +{ return json_encode($array); } @@ -1137,7 +1168,7 @@ function markUpBreadcrumbList($items) "name" => $index, ]; if ($item != '' || $item != null) { - $json[$i-1]['item'] = $item; + $json[$i - 1]['item'] = $item; } } @@ -1166,9 +1197,9 @@ RESULT; */ function fixUrlLang($url) { - if ( config('app.xlang.active') && app()->getLocale() != config('app.xlang.main')){ + if (config('app.xlang.active') && app()->getLocale() != config('app.xlang.main')) { $welcome = \route('client.welcome'); - return str_replace($welcome,$welcome .'/'.app()->getLocale(),$url); + return str_replace($welcome, $welcome . '/' . app()->getLocale(), $url); } return $url; } diff --git a/app/Http/Controllers/Admin/AreaController.php b/app/Http/Controllers/Admin/AreaController.php index 6d7ba1e..3f4b6b0 100644 --- a/app/Http/Controllers/Admin/AreaController.php +++ b/app/Http/Controllers/Admin/AreaController.php @@ -20,8 +20,6 @@ class AreaController extends Controller public function desgin(Area $area) { - - $valids = []; foreach ($area->segment as $seg) { if (File::exists(resource_path() . '/views/segments/' . $seg)) { diff --git a/database/seeders/PartSeeder.php b/database/seeders/PartSeeder.php index 364aa7e..eca39b4 100644 --- a/database/seeders/PartSeeder.php +++ b/database/seeders/PartSeeder.php @@ -87,7 +87,7 @@ class PartSeeder extends Seeder $part = new Part(); $part->segment = 'menu'; $part->part = 'AplMenu'; - $part->area_id = Area::where('name', 'index')->first()->id; + $part->area_id = Area::where('name', 'default_header')->first()->id; $part->sort = 0; $part->save(); diff --git a/resources/views/segments/menu/AplMenu/AplMenu.blade.php b/resources/views/segments/menu/AplMenu/AplMenu.blade.php index 4fb6eae..9955c99 100644 --- a/resources/views/segments/menu/AplMenu/AplMenu.blade.php +++ b/resources/views/segments/menu/AplMenu/AplMenu.blade.php @@ -7,7 +7,7 @@ - @foreach(getMenuBySetting($data->area->name.'_'.$data->part.'_menu')->items as $item) + @foreach(getMenuBySettingItems($data->area->name.'_'.$data->part.'_menu') as $item)
- {{getGroupBySetting($data->area->name.'_'.$data->part.'_group')->description}} + {{getGroupBySetting($data->area->name.'_'.$data->part.'_group')?->description}}
- {{getGroupBySetting($data->area->name.'_'.$data->part)->description}} + {{getGroupBySetting($data->area->name.'_'.$data->part)?->description}}