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

Commit f45431d

Browse files
committed
add getRouteData() for easier retrieve of route cached data
1 parent c3e0675 commit f45431d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ Ofcourse you are free to code your app the way you want, but just in-case here a
8686
| action | SomeController\camelCase(Some Title) | someTitle |
8787

8888
## Notes
89-
- you can get any page params like (**template, title, body, desc, breadCrump**) by using `extract(cache('the_route_name'));`
89+
- you can get any page params like (**template, title, body, desc, breadCrump**) by using `extract(SimpleMenu::getRouteData('the-route-name'));`
9090

9191
<u>**or**</u>
9292

93-
- if you followed the naming convention above and you are inside the `page action method`, you can instead use `extract(cache(kebab_case('TheCurrentMethodName')));`
93+
- if you followed the naming convention above and you are inside the `page action method`, you can instead use `extract(SimpleMenu::getRouteData(kebab_case('theCurrentMethodName')));`
9494

9595
| method name | format | output = route_name |
9696
|-------------|-------------------------|---------------------|

src/Controller/DummyController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace ctf0\SimpleMenu\Controller;
44

55
use App\Http\Controllers\Controller;
6+
use ctf0\SimpleMenu\Facade\SimpleMenu;
67
use Illuminate\Support\Facades\Route;
7-
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
88

99
class DummyController extends Controller
1010
{
1111
public function handle()
1212
{
13-
extract(cache(LaravelLocalization::getCurrentLocale().'-'.Route::currentRouteName()));
13+
extract(SimpleMenu::getRouteData(Route::currentRouteName()));
1414

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

src/Traits/NavigationTrait.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getRoute($crntRouteName, array $params = null)
7272
// fix link not being 'is-active' when "hideDefaultLocaleInURL => true"
7373
if (LaravelLocalization::hideDefaultLocaleInURL() && $code == LaravelLocalization::getDefaultLocale()) {
7474
$finalUrl = LaravelLocalization::getLocalizedURL($code, url($this->getParams($url, $value)), []);
75-
}else {
75+
} else {
7676
$finalUrl = LaravelLocalization::getLocalizedURL($code, url($this->getParams($url, $value)), [], true);
7777
}
7878

@@ -88,7 +88,7 @@ public function getRoute($crntRouteName, array $params = null)
8888
}
8989

9090
/**
91-
* helper.
91+
* helpers.
9292
*
9393
* @return [type] [description]
9494
*/
@@ -97,6 +97,11 @@ public function urlRoute()
9797
return $this->urlRoute;
9898
}
9999

100+
public function getRouteData($name)
101+
{
102+
return cache(LaravelLocalization::getCurrentLocale().'-'.$name);
103+
}
104+
100105
/**
101106
* resolve route url.
102107
*

0 commit comments

Comments
 (0)