Skip to content

Commit

Permalink
added hide menu category and group
Browse files Browse the repository at this point in the history
  • Loading branch information
A1Gard committed Dec 27, 2024
1 parent eedc1a7 commit d2e5dc4
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function save($category, $request)
$category->subtitle = $request->input('subtitle');
$category->icon = $request->input('icon');
$category->description = $request->input('description');
$category->hide = $request->has('hide');

if ($request->input('parent_id') == ''){
$category->parent_id = null;
}else{
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Admin/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function save($group, $request)
$group->name = $request->input('name');
$group->subtitle = $request->input('subtitle');
$group->description = $request->input('description');
$group->hide = $request->has('hide');

if ($request->input('parent_id') == ''){
$group->parent_id = null;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Admin/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function save($post, $request)
$post->media()->delete();
$post->addMedia($request->file('image'))
->preservingOriginal() //middle method

->toMediaCollection(); //finishing method
}

Expand Down
14 changes: 10 additions & 4 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ public function products()

public function published($limit = 10, $order = 'id', $dir = 'DESC')
{
return $this->products()->where('status', 1)
return $this->products()->where('status', 1)
->orderBy($order, $dir)->limit($limit)->get([
DB::raw('name as "title"'),
'slug'
]);
'name',
'slug',
])->map(function ($item) {
// Change 'name' to 'title'
$item->title = $item->name; // Add title property
unset($item->name); // Remove the old name property
return $item; // Return the modified item
});

}

public function evaluations(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function up(): void
$table->unsignedInteger('parent_id')->nullable()->default(null)->index();
$table->json('theme')->nullable();
$table->text('canonical')->nullable();
$table->boolean('hide')->default(true)->comment('hide in menu as sub group');
$table->softDeletes();
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function up(): void
$table->unsignedInteger('parent_id')->nullable()->default(null)->index();
$table->json('theme')->nullable();
$table->text('canonical')->nullable();
$table->boolean('hide')->default(true)->comment('hide in menu as sub category');
$table->softDeletes();
$table->timestamps();
});
Expand Down
8 changes: 7 additions & 1 deletion docs/5-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@ The `Group` model is designed to categorize content in your application. It allo
- **Type:** Text (Nullable)
- **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.


### 12. `hide`
- **Type:** Boolean
- **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,
- if it is set to `true`, it will be hidden from display. The default value is `false`.

---
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.
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.
6 changes: 5 additions & 1 deletion docs/8-category.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ The `Category` model is used to categorize products within your application. Thi
- **Type:** Text (Nullable)
- **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.

### 14. `hide`
- **Type:** Boolean
- **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`.

---
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.
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.
12 changes: 11 additions & 1 deletion resources/views/admin/categories/category-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class="form-control">
<input name="slug" type="text" class="form-control @error('slug') is-invalid @enderror"
placeholder="{{__('Category slug')}}" value="{{old('slug',$item->slug??null)}}"/>
</div>
<div class="col-md-12 mt-3">
<div class="col-md-9 mt-3">
<div class="form-group">
<label for="subtitle">
{{__('Subtitle')}}
Expand All @@ -128,6 +128,16 @@ class="form-control @error('subtitle') is-invalid @enderror" id="subtitle"
value="{{old('subtitle',$item->subtitle??null)}}"/>
</div>
</div>
<div class="col-md-3 mt-4">
<div class="form-group mt-4">
<div class="form-check form-switch">
<input class="form-check-input" name="hide" @if (old('hide',$item->hide??0) != 0)
checked
@endif type="checkbox" id="hide">
<label class="form-check-label" for="hide">{{__('Hide in menu')}}</label>
</div>
</div>
</div>
<div class="col-md-3 mt-3">
<label for="parent">
{{__('Group Parent')}}
Expand Down
13 changes: 12 additions & 1 deletion resources/views/admin/groups/group-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class="form-control">
<input name="slug" type="text" class="form-control @error('slug') is-invalid @enderror"
placeholder="{{__('Group slug')}}" value="{{old('slug',$item->slug??null)}}"/>
</div>
<div class="col-md-12 mt-3">
<div class="col-md-9 mt-3">
<div class="form-group">
<label for="subtitle">
{{__('Subtitle')}}
Expand All @@ -106,6 +106,17 @@ class="form-control @error('subtitle') is-invalid @enderror" id="subtitle"
value="{{old('subtitle',$item->subtitle??null)}}"/>
</div>
</div>
<div class="col-md-3 mt-4">
<div class="form-group mt-4">
<div class="form-check form-switch">
<input class="form-check-input" name="hide" @if (old('hide',$item->hide??0) != 0)
checked
@endif type="checkbox" id="hide">
<label class="form-check-label" for="hide">{{__('Hide in menu')}}</label>
</div>
</div>
</div>

<div class="col-md-4 mt-3">
<label for="parent">
{{__('Group Parent')}}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/segments/menu/AplMenu/AplMenu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</li>
@endforeach
@else
@foreach($item->dest->children as $itm)
@foreach($item->dest->children()->where('hide',false)->get() as $itm)
<li>
<a href="{{$itm->webUrl()}}">
{{$itm->name}}
Expand All @@ -51,7 +51,7 @@

<li>
<a href="{{$itm->webUrl()}}">
{{\Illuminate\Support\Str::limit($itm->title,25)}}
{{\Illuminate\Support\Str::limit(($itm->title),25)}}
</a>
</li>
@endforeach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
@switch($item->menuable_type)
@case(\App\Models\Group::class)
@case(\App\Models\Category::class)
@if($item->dest->children()->count() > 0)
@if($item->dest->children()->where('hide',false)->count() > 0)
<ul class="sub-menu-item">
@foreach($item->dest->children as $itm)
@foreach($item->dest->children()->where('hide',false)->get() as $itm)
<li>
<a href="{{$itm->webUrl()}}">
{{$itm->name}}
Expand Down

0 comments on commit d2e5dc4

Please sign in to comment.