Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
4.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ctf0 committed Sep 13, 2019
1 parent c864edf commit 1e760a4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
}
],
"require": {
"php" : "~7.0",
"illuminate/support": "5.4 - 5.8",
"php": "~7.0",
"illuminate/support": "5.4 - 6.0",
"gazsp/baum": "*",
"mcamara/laravel-localization": "*",
"spatie/laravel-permission": "*",
Expand Down
13 changes: 7 additions & 6 deletions src/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ctf0\SimpleMenu\Controllers;

use Illuminate\Support\Arr;
use App\Http\Controllers\Controller;
use ctf0\SimpleMenu\Controllers\Admin\Traits\Paginate;

Expand Down Expand Up @@ -30,12 +31,12 @@ public function __construct()

$this->cache = app('cache');
$this->adminPath = 'SimpleMenu::admin';
$this->crud_prefix = array_get($sm_config, 'crud_prefix');
$this->userModel = app(array_get($sm_config, 'models.user'));
$this->pageModel = app(array_get($sm_config, 'models.page'));
$this->menuModel = app(array_get($sm_config, 'models.menu'));
$this->crud_prefix = $sm_config['crud_prefix'];

$this->roleModel = app(array_get($sp_config, 'models.role'));
$this->permissionModel = app(array_get($sp_config, 'models.permission'));
$this->userModel = app(Arr::get($sm_config, 'models.user'));
$this->pageModel = app(Arr::get($sm_config, 'models.page'));
$this->menuModel = app(Arr::get($sm_config, 'models.menu'));
$this->roleModel = app(Arr::get($sp_config, 'models.role'));
$this->permissionModel = app(Arr::get($sp_config, 'models.permission'));
}
}
3 changes: 2 additions & 1 deletion src/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ctf0\SimpleMenu\Models;

use Baum\Node;
use Illuminate\Support\Arr;
use Spatie\Permission\Traits\HasRoles;
use Spatie\Translatable\HasTranslations;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand Down Expand Up @@ -87,7 +88,7 @@ public function getAncestors($columns = ['*'])
public function getNestsAttribute()
{
return app('cache')->tags('sm')->rememberForever($this->getCrntLocale() . "-{$this->route_name}_nests", function () {
return array_flatten(current($this->getDescendants()->toHierarchy()));
return Arr::flatten(current($this->getDescendants()->toHierarchy()));
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/SimpleMenuServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ protected function observers()
$models = $this->app['config']->get('simpleMenu.models');

if ($models) {
$this->app->make(array_get($models, 'page'))->observe(PageObserver::class);
$this->app->make(array_get($models, 'menu'))->observe(MenuObserver::class);
$this->app->make(array_get($models, 'user'))->observe(UserObserver::class);
$this->app->make($models['page'])->observe(PageObserver::class);
$this->app->make($models['menu'])->observe(MenuObserver::class);
$this->app->make($models['user'])->observe(UserObserver::class);
}
}

Expand Down
23 changes: 13 additions & 10 deletions src/Traits/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ctf0\SimpleMenu\Traits;

use Illuminate\Support\Arr;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;

trait Navigation
Expand All @@ -22,14 +23,16 @@ public function getUrl($code)

// redir to '/' if the first item in "bc" is in diff locale
$bc = $this->getRouteData($name)['breadCrumb'];

if (isset($bc) && count($bc) && !$this->searchForRoute($bc->pluck('route_name')->first(), $code)) {
return LaravelLocalization::getLocalizedURL($code, url('/'), [], true);
}

// routeName is not saved in the db (ex.php artisan make:auth)
// or only url
$routesListFile = include $this->listFileDir;
if (is_null($name) || !array_get($routesListFile, $name)) {

if (is_null($name) || !isset($routesListFile[$name])) {
return LaravelLocalization::getLocalizedURL($code, null, [], true);
}

Expand All @@ -54,7 +57,7 @@ public function getUrl($code)
*
* @return [type] [description]
*/
public function getRoute($crntRouteName, array $params = null)
public function getRoute($crntRouteName, $params = null)
{
// where route is available under one locale but not the other
if (!app('router')->has($crntRouteName)) {
Expand All @@ -71,7 +74,7 @@ public function getRoute($crntRouteName, array $params = null)
if ($crntRouteName == $key) {
session([$key => $value]);

// fix link not being 'is-active' when "hideDefaultLocaleInURL => true"
// fix link not being 'is-active'when"hideDefaultLocaleInURL => true"
$finalUrl = LaravelLocalization::getLocalizedURL($locale, url($this->getParams($url, $value)), [], $forceDefaultLocation);
$this->urlRoute = $finalUrl;

Expand Down Expand Up @@ -146,7 +149,7 @@ protected function searchForRoute($name, $code)
$routesListFile = include $this->listFileDir;

// check if we have a link according to that "routeName & code"
return array_get($routesListFile, "$name.$code", false);
return Arr::get($routesListFile, "$name.$code", false);
}

/**
Expand All @@ -170,9 +173,9 @@ public function render($pages, $classes = null, $params = null)
$a = config('simpleMenu.listClasses.a');
break;
default:
$ul = array_get($classes, 'ul');
$li = array_get($classes, 'li');
$a = array_get($classes, 'a');
$ul = $classes['ul'];
$li = $classes['li'];
$a = $classes['a'];
break;
}

Expand All @@ -194,7 +197,7 @@ public function render($pages, $classes = null, $params = null)
protected function getHtml($pages, $ul_ClassName, $li_ClassName, $a_ClassName, $params, $url)
{
$html = '';
$html .= "<ul class=\"{$ul_ClassName}\">";
$html .= "<ul class = \"{$ul_ClassName}\">";

foreach ($pages as $page) {
// escape empty url
Expand All @@ -205,8 +208,8 @@ protected function getHtml($pages, $ul_ClassName, $li_ClassName, $a_ClassName, $
$routeUrl = $this->getRoute($page->route_name, $params);
$isActive = ($url == $routeUrl ? $a_ClassName : '');

$html .= "<li class=\"{$li_ClassName}\">";
$html .= "<a href=\"{$routeUrl}\" class=\"{$isActive}\">{$page->title}</a>";
$html .= "<li class = \"{$li_ClassName}\">";
$html .= "<a href = \"{$routeUrl}\" class = \"{$isActive}\">{$page->title}</a>";

if ($childs = $page->nests) {
$html .= $this->getHtml($childs, $ul_ClassName, $li_ClassName, $a_ClassName, $params, $url);
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/Ops.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ protected function createCaches()
$models = config('simpleMenu.models');

$this->cache->tags('sm')->rememberForever('menus', function () use ($models) {
return app(array_get($models, 'menu'))->with('pages')->get();
return app($models['menu'])->with('pages')->get();
});

$this->cache->tags('sm')->rememberForever('pages', function () use ($models) {
return app(array_get($models, 'page'))->withTrashed()->get();
return app($models['page'])->withTrashed()->get();
});

$this->cache->rememberForever('sm-users', function () use ($models) {
return app(array_get($models, 'user'))->with(['roles', 'permissions'])->get();
return app($models['user'])->with(['roles', 'permissions'])->get();
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/Traits/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ctf0\SimpleMenu\Traits;

use Illuminate\Support\Arr;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;

trait Routes
Expand Down Expand Up @@ -93,7 +94,7 @@ protected function routeGen($page)
? starts_with($action, '\\') ? $action : "\\$action"
: '\ctf0\SimpleMenu\Controllers\DummyController@handle';

$mds = array_filter(array_flatten([$middlewares, $roles, $permissions]));
$mds = array_filter(Arr::flatten([$middlewares, $roles, $permissions]));

app('router')->get($route)
->uses($uses)
Expand Down

0 comments on commit 1e760a4

Please sign in to comment.