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

Commit 1e760a4

Browse files
committed
4.1.2
1 parent c864edf commit 1e760a4

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
}
2020
],
2121
"require": {
22-
"php" : "~7.0",
23-
"illuminate/support": "5.4 - 5.8",
22+
"php": "~7.0",
23+
"illuminate/support": "5.4 - 6.0",
2424
"gazsp/baum": "*",
2525
"mcamara/laravel-localization": "*",
2626
"spatie/laravel-permission": "*",

src/Controllers/BaseController.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ctf0\SimpleMenu\Controllers;
44

5+
use Illuminate\Support\Arr;
56
use App\Http\Controllers\Controller;
67
use ctf0\SimpleMenu\Controllers\Admin\Traits\Paginate;
78

@@ -30,12 +31,12 @@ public function __construct()
3031

3132
$this->cache = app('cache');
3233
$this->adminPath = 'SimpleMenu::admin';
33-
$this->crud_prefix = array_get($sm_config, 'crud_prefix');
34-
$this->userModel = app(array_get($sm_config, 'models.user'));
35-
$this->pageModel = app(array_get($sm_config, 'models.page'));
36-
$this->menuModel = app(array_get($sm_config, 'models.menu'));
34+
$this->crud_prefix = $sm_config['crud_prefix'];
3735

38-
$this->roleModel = app(array_get($sp_config, 'models.role'));
39-
$this->permissionModel = app(array_get($sp_config, 'models.permission'));
36+
$this->userModel = app(Arr::get($sm_config, 'models.user'));
37+
$this->pageModel = app(Arr::get($sm_config, 'models.page'));
38+
$this->menuModel = app(Arr::get($sm_config, 'models.menu'));
39+
$this->roleModel = app(Arr::get($sp_config, 'models.role'));
40+
$this->permissionModel = app(Arr::get($sp_config, 'models.permission'));
4041
}
4142
}

src/Models/Page.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ctf0\SimpleMenu\Models;
44

55
use Baum\Node;
6+
use Illuminate\Support\Arr;
67
use Spatie\Permission\Traits\HasRoles;
78
use Spatie\Translatable\HasTranslations;
89
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -87,7 +88,7 @@ public function getAncestors($columns = ['*'])
8788
public function getNestsAttribute()
8889
{
8990
return app('cache')->tags('sm')->rememberForever($this->getCrntLocale() . "-{$this->route_name}_nests", function () {
90-
return array_flatten(current($this->getDescendants()->toHierarchy()));
91+
return Arr::flatten(current($this->getDescendants()->toHierarchy()));
9192
});
9293
}
9394

src/SimpleMenuServiceProvider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ protected function observers()
7373
$models = $this->app['config']->get('simpleMenu.models');
7474

7575
if ($models) {
76-
$this->app->make(array_get($models, 'page'))->observe(PageObserver::class);
77-
$this->app->make(array_get($models, 'menu'))->observe(MenuObserver::class);
78-
$this->app->make(array_get($models, 'user'))->observe(UserObserver::class);
76+
$this->app->make($models['page'])->observe(PageObserver::class);
77+
$this->app->make($models['menu'])->observe(MenuObserver::class);
78+
$this->app->make($models['user'])->observe(UserObserver::class);
7979
}
8080
}
8181

src/Traits/Navigation.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ctf0\SimpleMenu\Traits;
44

5+
use Illuminate\Support\Arr;
56
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
67

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

2324
// redir to '/' if the first item in "bc" is in diff locale
2425
$bc = $this->getRouteData($name)['breadCrumb'];
26+
2527
if (isset($bc) && count($bc) && !$this->searchForRoute($bc->pluck('route_name')->first(), $code)) {
2628
return LaravelLocalization::getLocalizedURL($code, url('/'), [], true);
2729
}
2830

2931
// routeName is not saved in the db (ex.php artisan make:auth)
3032
// or only url
3133
$routesListFile = include $this->listFileDir;
32-
if (is_null($name) || !array_get($routesListFile, $name)) {
34+
35+
if (is_null($name) || !isset($routesListFile[$name])) {
3336
return LaravelLocalization::getLocalizedURL($code, null, [], true);
3437
}
3538

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

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

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

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

152155
/**
@@ -170,9 +173,9 @@ public function render($pages, $classes = null, $params = null)
170173
$a = config('simpleMenu.listClasses.a');
171174
break;
172175
default:
173-
$ul = array_get($classes, 'ul');
174-
$li = array_get($classes, 'li');
175-
$a = array_get($classes, 'a');
176+
$ul = $classes['ul'];
177+
$li = $classes['li'];
178+
$a = $classes['a'];
176179
break;
177180
}
178181

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

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

208-
$html .= "<li class=\"{$li_ClassName}\">";
209-
$html .= "<a href=\"{$routeUrl}\" class=\"{$isActive}\">{$page->title}</a>";
211+
$html .= "<li class = \"{$li_ClassName}\">";
212+
$html .= "<a href = \"{$routeUrl}\" class = \"{$isActive}\">{$page->title}</a>";
210213

211214
if ($childs = $page->nests) {
212215
$html .= $this->getHtml($childs, $ul_ClassName, $li_ClassName, $a_ClassName, $params, $url);

src/Traits/Ops.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ protected function createCaches()
2929
$models = config('simpleMenu.models');
3030

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

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

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

src/Traits/Routes.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ctf0\SimpleMenu\Traits;
44

5+
use Illuminate\Support\Arr;
56
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
67

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

96-
$mds = array_filter(array_flatten([$middlewares, $roles, $permissions]));
97+
$mds = array_filter(Arr::flatten([$middlewares, $roles, $permissions]));
9798

9899
app('router')->get($route)
99100
->uses($uses)

0 commit comments

Comments
 (0)