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

Commit c3e0675

Browse files
committed
fixed route caching
1 parent d69ccf5 commit c3e0675

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/Controller/DummyController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
use App\Http\Controllers\Controller;
66
use Illuminate\Support\Facades\Route;
7+
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
78

89
class DummyController extends Controller
910
{
1011
public function handle()
1112
{
12-
extract(cache(Route::currentRouteName()));
13+
extract(cache(LaravelLocalization::getCurrentLocale().'-'.Route::currentRouteName()));
1314

1415
return view(config('simpleMenu.templatePath').".$template", compact('title', 'body', 'desc', 'breadCrump'));
1516
}

src/Models/Page.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Page extends Node
1313
{
1414
use HasRoles, HasTranslations;
1515

16-
protected $guarded = ['id'];
16+
protected $guarded = ['id'];
1717
public $translatable = ['title', 'body', 'desc', 'prefix', 'url'];
1818

1919
public static function boot()
@@ -30,9 +30,9 @@ public static function boot()
3030
$name = "{$item}Menu-{$code}Pages";
3131
Cache::forget($name);
3232
});
33+
Cache::forget("{$code}-{$model->route_name}");
3334
}
3435

35-
Cache::forget($model->route_name);
3636
File::delete(config('simpleMenu.routeListPath'));
3737
});
3838

@@ -42,9 +42,9 @@ public static function boot()
4242
$name = "{$item}Menu-{$code}Pages";
4343
Cache::forget($name);
4444
});
45+
Cache::forget("{$code}-{$model->route_name}");
4546
}
4647

47-
Cache::forget($model->route_name);
4848
File::delete(config('simpleMenu.routeListPath'));
4949
});
5050
}

src/Traits/RoutesTrait.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function createRoutes()
3434
protected function utilCheck()
3535
{
3636
if (!File::exists($this->listFileDir)) {
37-
$this->localeCodes = array_keys(LaravelLocalization::getSupportedLocales());
37+
$this->localeCodes = array_keys(LaravelLocalization::getSupportedLocales());
3838
$this->listFileFound = false;
3939

4040
$this->utilLoop();
@@ -60,20 +60,20 @@ protected function utilLoop()
6060
protected function pageComp($page)
6161
{
6262
// page data
63-
$title = $page->title;
64-
$body = $page->body;
65-
$desc = $page->desc;
66-
$template = $page->template;
63+
$title = $page->title;
64+
$body = $page->body;
65+
$desc = $page->desc;
66+
$template = $page->template;
6767
$breadCrump = $page->getAncestors();
6868

6969
// route data
70-
$url = $page->getTranslationWithoutFallback('url', app()->getLocale());
71-
$action = $page->action;
72-
$prefix = $page->getTranslationWithoutFallback('prefix', app()->getLocale());
70+
$url = $page->getTranslationWithoutFallback('url', app()->getLocale());
71+
$action = $page->action;
72+
$prefix = $page->getTranslationWithoutFallback('prefix', app()->getLocale());
7373
$routeName = $page->route_name;
7474

7575
// middlewares
76-
$roles = 'role:'.implode(',', $page->roles()->pluck('name')->toArray());
76+
$roles = 'role:'.implode(',', $page->roles()->pluck('name')->toArray());
7777
$permissions = 'perm:'.implode(',', $page->permissions()->pluck('name')->toArray());
7878

7979
// make route
@@ -92,7 +92,7 @@ protected function routeGen($routeName, $url, $prefix, $action, $roles, $permiss
9292
}
9393

9494
// cache the page so we pass the page params to the controller@method
95-
Cache::rememberForever($routeName, function () use ($template, $title, $body, $desc, $breadCrump) {
95+
Cache::rememberForever(LaravelLocalization::getCurrentLocale().'-'.$routeName, function () use ($template, $title, $body, $desc, $breadCrump) {
9696
return compact('template', 'title', 'body', 'desc', 'breadCrump');
9797
});
9898

@@ -117,7 +117,7 @@ protected function routeGen($routeName, $url, $prefix, $action, $roles, $permiss
117117
protected function createRoutesList($action, $page, $routeName)
118118
{
119119
foreach ($this->localeCodes as $code) {
120-
$url = $page->getTranslationWithoutFallback('url', $code);
120+
$url = $page->getTranslationWithoutFallback('url', $code);
121121
$prefix = $page->getTranslationWithoutFallback('prefix', $code);
122122

123123
if ($this->escapeEmptyRoute($url)) {

src/views/breadCrump.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
@foreach ($items as $one)
33
@include('SimpleMenu::partials.r_params')
44

5-
<li>
6-
<a href="{{ SimpleMenu::urlRoute() }}" class="{{ request()->url() == SimpleMenu::urlRoute() ? 'is-active' : '' }}">
5+
<li class="{{ request()->url() == SimpleMenu::urlRoute() ? 'is-active' : '' }}">
6+
<a href="{{ SimpleMenu::urlRoute() }}">
77
{{ $one->title }}
88
</a>
99
</li>

0 commit comments

Comments
 (0)