Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d2e5dc4

Browse files
committedDec 27, 2024·
added hide menu category and group
1 parent eedc1a7 commit d2e5dc4

12 files changed

+55
-12
lines changed
 

‎app/Http/Controllers/Admin/CategoryController.php

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function save($category, $request)
6060
$category->subtitle = $request->input('subtitle');
6161
$category->icon = $request->input('icon');
6262
$category->description = $request->input('description');
63+
$category->hide = $request->has('hide');
64+
6365
if ($request->input('parent_id') == ''){
6466
$category->parent_id = null;
6567
}else{

‎app/Http/Controllers/Admin/GroupController.php

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function save($group, $request)
5858
$group->name = $request->input('name');
5959
$group->subtitle = $request->input('subtitle');
6060
$group->description = $request->input('description');
61+
$group->hide = $request->has('hide');
6162

6263
if ($request->input('parent_id') == ''){
6364
$group->parent_id = null;

‎app/Http/Controllers/Admin/PostController.php

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function save($post, $request)
8484
$post->media()->delete();
8585
$post->addMedia($request->file('image'))
8686
->preservingOriginal() //middle method
87+
8788
->toMediaCollection(); //finishing method
8889
}
8990

‎app/Models/Category.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ public function products()
9696

9797
public function published($limit = 10, $order = 'id', $dir = 'DESC')
9898
{
99-
return $this->products()->where('status', 1)
99+
return $this->products()->where('status', 1)
100100
->orderBy($order, $dir)->limit($limit)->get([
101-
DB::raw('name as "title"'),
102-
'slug'
103-
]);
101+
'name',
102+
'slug',
103+
])->map(function ($item) {
104+
// Change 'name' to 'title'
105+
$item->title = $item->name; // Add title property
106+
unset($item->name); // Remove the old name property
107+
return $item; // Return the modified item
108+
});
109+
104110
}
105111

106112
public function evaluations(){

‎database/migrations/2024_05_07_123332_create_groups_table.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function up(): void
2323
$table->unsignedInteger('parent_id')->nullable()->default(null)->index();
2424
$table->json('theme')->nullable();
2525
$table->text('canonical')->nullable();
26+
$table->boolean('hide')->default(true)->comment('hide in menu as sub group');
2627
$table->softDeletes();
2728
$table->timestamps();
2829
});

‎database/migrations/2024_05_07_125838_create_categories_table.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function up(): void
2525
$table->unsignedInteger('parent_id')->nullable()->default(null)->index();
2626
$table->json('theme')->nullable();
2727
$table->text('canonical')->nullable();
28+
$table->boolean('hide')->default(true)->comment('hide in menu as sub category');
2829
$table->softDeletes();
2930
$table->timestamps();
3031
});

‎docs/5-group.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ The `Group` model is designed to categorize content in your application. It allo
4848
- **Type:** Text (Nullable)
4949
- **Description:** This field is used for SEO (Search Engine Optimization) purposes. It helps in directing the search engine’s authority of a group to another page, enhancing the SEO power of that group. This is particularly useful for managing duplicate content.
5050

51+
52+
### 12. `hide`
53+
- **Type:** Boolean
54+
- **Description:** This field is used to hide the category in the site menu. Essentially, if this option is set to `false`, the group will be displayed as a submenu in the menu. However,
55+
- if it is set to `true`, it will be hidden from display. The default value is `false`.
56+
5157
---
52-
By utilizing this `Group` model, you can effectively organize your content in a way that is user-friendly and conducive to SEO, providing a better experience for your users.
58+
By utilizing this `Group` model, you can effectively organize your content in a way that is user-friendly and conducive to SEO, providing a better experience for your users.

‎docs/8-category.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@ The `Category` model is used to categorize products within your application. Thi
5656
- **Type:** Text (Nullable)
5757
- **Description:** This field is used for SEO (Search Engine Optimization) purposes. It helps in transferring the search engine authority of the category to another page, enhancing the SEO potential of that category. This is particularly useful for managing duplicate content.
5858

59+
### 14. `hide`
60+
- **Type:** Boolean
61+
- **Description:** This field is used to hide the category in the site menu. Essentially, if this option is set to `false`, the category will be displayed as a submenu in the menu. However, if it is set to `true`, it will be hidden from display. The default value is `false`.
62+
5963
---
60-
By utilizing this `Category` model, you can effectively organize your product categories in a structured way, enhancing user experience and improving SEO, while offering flexibility with images and icons.
64+
By utilizing this `Category` model, you can effectively organize your product categories in a structured way, enhancing user experience and improving SEO, while offering flexibility with images and icons.

‎resources/views/admin/categories/category-form.blade.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class="form-control">
117117
<input name="slug" type="text" class="form-control @error('slug') is-invalid @enderror"
118118
placeholder="{{__('Category slug')}}" value="{{old('slug',$item->slug??null)}}"/>
119119
</div>
120-
<div class="col-md-12 mt-3">
120+
<div class="col-md-9 mt-3">
121121
<div class="form-group">
122122
<label for="subtitle">
123123
{{__('Subtitle')}}
@@ -128,6 +128,16 @@ class="form-control @error('subtitle') is-invalid @enderror" id="subtitle"
128128
value="{{old('subtitle',$item->subtitle??null)}}"/>
129129
</div>
130130
</div>
131+
<div class="col-md-3 mt-4">
132+
<div class="form-group mt-4">
133+
<div class="form-check form-switch">
134+
<input class="form-check-input" name="hide" @if (old('hide',$item->hide??0) != 0)
135+
checked
136+
@endif type="checkbox" id="hide">
137+
<label class="form-check-label" for="hide">{{__('Hide in menu')}}</label>
138+
</div>
139+
</div>
140+
</div>
131141
<div class="col-md-3 mt-3">
132142
<label for="parent">
133143
{{__('Group Parent')}}

‎resources/views/admin/groups/group-form.blade.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class="form-control">
9595
<input name="slug" type="text" class="form-control @error('slug') is-invalid @enderror"
9696
placeholder="{{__('Group slug')}}" value="{{old('slug',$item->slug??null)}}"/>
9797
</div>
98-
<div class="col-md-12 mt-3">
98+
<div class="col-md-9 mt-3">
9999
<div class="form-group">
100100
<label for="subtitle">
101101
{{__('Subtitle')}}
@@ -106,6 +106,17 @@ class="form-control @error('subtitle') is-invalid @enderror" id="subtitle"
106106
value="{{old('subtitle',$item->subtitle??null)}}"/>
107107
</div>
108108
</div>
109+
<div class="col-md-3 mt-4">
110+
<div class="form-group mt-4">
111+
<div class="form-check form-switch">
112+
<input class="form-check-input" name="hide" @if (old('hide',$item->hide??0) != 0)
113+
checked
114+
@endif type="checkbox" id="hide">
115+
<label class="form-check-label" for="hide">{{__('Hide in menu')}}</label>
116+
</div>
117+
</div>
118+
</div>
119+
109120
<div class="col-md-4 mt-3">
110121
<label for="parent">
111122
{{__('Group Parent')}}

‎resources/views/segments/menu/AplMenu/AplMenu.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</li>
3333
@endforeach
3434
@else
35-
@foreach($item->dest->children as $itm)
35+
@foreach($item->dest->children()->where('hide',false)->get() as $itm)
3636
<li>
3737
<a href="{{$itm->webUrl()}}">
3838
{{$itm->name}}
@@ -51,7 +51,7 @@
5151

5252
<li>
5353
<a href="{{$itm->webUrl()}}">
54-
{{\Illuminate\Support\Str::limit($itm->title,25)}}
54+
{{\Illuminate\Support\Str::limit(($itm->title),25)}}
5555
</a>
5656
</li>
5757
@endforeach

‎resources/views/segments/menu/HomayonMenu/HomayonMenu.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@
9696
@switch($item->menuable_type)
9797
@case(\App\Models\Group::class)
9898
@case(\App\Models\Category::class)
99-
@if($item->dest->children()->count() > 0)
99+
@if($item->dest->children()->where('hide',false)->count() > 0)
100100
<ul class="sub-menu-item">
101-
@foreach($item->dest->children as $itm)
101+
@foreach($item->dest->children()->where('hide',false)->get() as $itm)
102102
<li>
103103
<a href="{{$itm->webUrl()}}">
104104
{{$itm->name}}

0 commit comments

Comments
 (0)
Please sign in to comment.