⚗️ Ajoute un menu dynamique pour avoir la classe active automatique
This commit is contained in:
parent
4bc1c97006
commit
a9f40e55e7
@ -2,7 +2,28 @@
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\Authenticate;
|
||||
use App\Http\Middleware\CheckForMaintenanceMode;
|
||||
use App\Http\Middleware\EncryptCookies;
|
||||
use App\Http\Middleware\GenerateMenus;
|
||||
use App\Http\Middleware\RedirectIfAuthenticated;
|
||||
use App\Http\Middleware\TrimStrings;
|
||||
use App\Http\Middleware\TrustProxies;
|
||||
use App\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
|
||||
use Illuminate\Auth\Middleware\Authorize;
|
||||
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
|
||||
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
|
||||
use Illuminate\Http\Middleware\SetCacheHeaders;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Routing\Middleware\ValidateSignature;
|
||||
use Illuminate\Session\Middleware\AuthenticateSession;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
@ -14,11 +35,11 @@ class Kernel extends HttpKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
TrustProxies::class,
|
||||
CheckForMaintenanceMode::class,
|
||||
ValidatePostSize::class,
|
||||
TrimStrings::class,
|
||||
ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -28,13 +49,14 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
GenerateMenus::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
@ -51,15 +73,15 @@ class Kernel extends HttpKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'auth' => Authenticate::class,
|
||||
'auth.basic' => AuthenticateWithBasicAuth::class,
|
||||
'bindings' => SubstituteBindings::class,
|
||||
'cache.headers' => SetCacheHeaders::class,
|
||||
'can' => Authorize::class,
|
||||
'guest' => RedirectIfAuthenticated::class,
|
||||
'signed' => ValidateSignature::class,
|
||||
'throttle' => ThrottleRequests::class,
|
||||
'verified' => EnsureEmailIsVerified::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -70,12 +92,12 @@ class Kernel extends HttpKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewarePriority = [
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\Authenticate::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\Illuminate\Auth\Middleware\Authorize::class,
|
||||
StartSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
Authenticate::class,
|
||||
ThrottleRequests::class,
|
||||
AuthenticateSession::class,
|
||||
SubstituteBindings::class,
|
||||
Authorize::class,
|
||||
];
|
||||
}
|
||||
|
40
app/Http/Middleware/GenerateMenus.php
Normal file
40
app/Http/Middleware/GenerateMenus.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Lavary\Menu\Builder;
|
||||
use Lavary\Menu\Menu;
|
||||
|
||||
class GenerateMenus
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
(new Menu)->make('menu', function (Builder $menu) {
|
||||
$accueil = $menu->add('Accueil', ['route' => 'dashboard', 'class' => 'nav-item'])->nickname('home');
|
||||
$accueil->link->attr(['class' => 'nav-link']);
|
||||
$accueil->prepend('<i class="fe fe-home"></i> ');
|
||||
$accueil->checkActivationStatus();
|
||||
|
||||
$stats = $menu->add('Mes statistiques', ['route' => 'stats', 'class' => 'nav-item'])->nickname('stats');
|
||||
$stats->link->attr(['class' => 'nav-link']);
|
||||
$stats->prepend('<i class="fe fe-trending-up"></i> ');
|
||||
$stats->checkActivationStatus();
|
||||
|
||||
$gallery = $menu->add('Ma gallerie', ['route' => 'gallery', 'class' => 'nav-item'])->nickname('gallery');
|
||||
$gallery->link->attr(['class' => 'nav-link']);
|
||||
$gallery->prepend('<i class="fe fe-image"></i> ');
|
||||
$gallery->checkActivationStatus();
|
||||
});
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
13
config/laravel-menu/settings.php
Normal file
13
config/laravel-menu/settings.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'auto_activate' => true,
|
||||
'activate_parents' => true,
|
||||
'active_class' => 'active',
|
||||
'restful' => false,
|
||||
'cascade_data' => true,
|
||||
'rest_base' => '', // string|array
|
||||
'active_element' => 'link', // item|link
|
||||
],
|
||||
];
|
5
config/laravel-menu/views.php
Normal file
5
config/laravel-menu/views.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'bootstrap-items' => 'laravel-menu::bootstrap-navbar-items',
|
||||
];
|
@ -101,15 +101,7 @@
|
||||
</div>
|
||||
<div class="col-lg order-lg-first">
|
||||
<ul class="nav nav-tabs border-0 flex-column flex-lg-row">
|
||||
<li class="nav-item">
|
||||
<a href="./" class="nav-link active"><i class="fe fe-home"></i> {{ __('Accueil') }}</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a href="#" class="nav-link"><i class="fe fe-trending-up"></i> {{ __('Mes statistiques') }}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="#" class="nav-link"><i class="fe fe-image"></i> {{ __('Ma gallerie') }}</a>
|
||||
</li>
|
||||
@include(config('laravel-menu.views.bootstrap-items'), ['items' => $menu->roots()])
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
20
resources/views/vendor/laravel-menu/bootstrap-navbar-items.blade.php
vendored
Normal file
20
resources/views/vendor/laravel-menu/bootstrap-navbar-items.blade.php
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
@foreach($items as $item)
|
||||
<li @lm_attrs($item) @if($item->hasChildren()) class="nav-item dropdown" @endif @lm_endattrs>
|
||||
@if($item->link) <a @lm_attrs($item->link) @if($item->hasChildren()) class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @else class="nav-link" @endif @lm_endattrs href="{!! $item->url() !!}">
|
||||
{!! $item->title !!}
|
||||
@if($item->hasChildren()) <b class="caret"></b> @endif
|
||||
</a>
|
||||
@else
|
||||
<span class="navbar-text">{!! $item->title !!}</span>
|
||||
@endif
|
||||
@if($item->hasChildren())
|
||||
<ul class="dropdown-menu">
|
||||
@include(config('laravel-menu.views.bootstrap-items'),
|
||||
array('items' => $item->children()))
|
||||
</ul>
|
||||
@endif
|
||||
</li>
|
||||
@if($item->divider)
|
||||
<li{!! Lavary\Menu\Builder::attributes($item->divider) !!}></li>
|
||||
@endif
|
||||
@endforeach
|
Loading…
Reference in New Issue
Block a user