Move the dashboard menu functionality to app/Models/DashboardMenu.php and allow for dropdown items

This commit is contained in:
Kevin MacMartin 2018-01-12 22:57:31 -05:00
parent b1533bb233
commit b55e0096c8
5 changed files with 66 additions and 10 deletions

View file

@ -0,0 +1,16 @@
<?php
namespace App\Models;
class DashboardMenu
{
/**
* Dashboard Menu
*
* @return array
*/
public static $menu = [
[ 'Contact', 'contact' ],
[ 'Subscriptions', 'subscriptions' ]
];
}

View file

@ -256,13 +256,20 @@ When a row is deleted, its respective image will be deleted as well if it exists
### Adding to the Dashboard Menu ### Adding to the Dashboard Menu
Add an array to the menu array in `resources/views/dashboard/elements/menu.blade.php` where the visible title as the first item and the model name as the second: Edit the `$menu` array in `app/Models/DashboardMenu.php` where the first column of each item is the title and the second is either a path, or an array of submenu items.
```php ```php
@set('menu', [ public static $menu = [
[ 'Page Name', 'model_name' ], [ 'Contact', 'contact' ],
[ 'Contact', 'contact' ] [ 'Subscriptions', 'subscriptions' ],
])
[
'Projects', [
[ 'Residential', 'projects-residential' ],
[ 'Commercial', 'projects-commercial' ]
]
]
];
``` ```
#### Additional Requirement for Delete Functionality #### Additional Requirement for Delete Functionality

View file

@ -98,7 +98,6 @@ body {
margin-bottom: 40px; margin-bottom: 40px;
.panel-body { .panel-body {
padding-bottom: 0px;
background-color: lighten($c-dashboard-light, 1%); background-color: lighten($c-dashboard-light, 1%);
@media (max-width: $screen-xs-max) { @media (max-width: $screen-xs-max) {

View file

@ -1,6 +1,21 @@
@extends('dashboard.core') @extends('dashboard.core')
@section('dashboard-body') @section('dashboard-body')
@set('menu_class', 'list-group-item') @foreach(App\Models\DashboardMenu::$menu as $menu_item)
<ul class="list-group linked-list">@include('dashboard.sections.menu')</ul> @if(is_array($menu_item[1]))
@foreach($menu_item[1] as $submenu_item)
<li class="list-group-item">
<a href="{{ url('/dashboard/' . $submenu_item[1]) }}">
{{ $menu_item[0] }}: {{ $submenu_item[0] }}
</a>
</li>
@endforeach
@else
<li class="list-group-item">
<a href="{{ url('/dashboard/' . $menu_item[1]) }}">
{{ $menu_item[0] }}
</a>
</li>
@endif
@endforeach
@endsection @endsection

View file

@ -22,8 +22,27 @@
<li><a href="{{ url('/register') }}">Register</a></li> <li><a href="{{ url('/register') }}">Register</a></li>
@endif @endif
@else @else
@set('menu_class', 'nav-item') @foreach(App\Models\DashboardMenu::$menu as $menu_item)
@include('dashboard.sections.menu') @if(is_array($menu_item[1]))
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ $menu_item[0] }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
@foreach($menu_item[1] as $submenu_item)
<li><a href="{{ url('/dashboard/' . $submenu_item[1]) }}">{{ $submenu_item[0] }}</a></li>
@endforeach
</ul>
</li>
@else
<li class="nav-item">
<a href="{{ url('/dashboard/' . $menu_item[1]) }}">
{{ $menu_item[0] }}
</a>
</li>
@endif
@endforeach
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">