Skip to content

Commit d7b1409

Browse files
KasparRosinmbaroncinicarolin.karing
authored
Nova 5 with Workbench (#192)
* feat: laravel nova 5 compatibility * feat: laravel nova 5 compatibility of outline nova multiselect filter * fix: mv laravel requesto to nova request inside parameters of filters * fix: various fixes due class updates on Nova 5 * fix: upfate readme and config to avoid closures * feat: add workbench * wip * Testing project * wip * feat: remove duplicate methods * allow callable --------- Co-authored-by: marco <[email protected]> Co-authored-by: carolin.karing <[email protected]>
1 parent 855746b commit d7b1409

File tree

24 files changed

+1429
-340
lines changed

24 files changed

+1429
-340
lines changed

README.md

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,12 @@ The locales are defined in the config file.
147147

148148
### Add links to front-end pages
149149

150-
To display a link to the actual page next to the slug, add or overwrite the closure in `config/nova-page-manager.php` for the key `base_url`.
150+
To display a link to the actual page next to the slug, add or overwrite the value in `config/nova-page-manager.php` for the key `base_url`.
151151

152152
```php
153153
// in /config/nova-page-manager.php
154154

155155
'base_url' => 'https://webshop.com', // Will add slugs to the end to make the URLs
156-
157-
// OR
158-
159-
'base_url' => function ($page) {
160-
return env('FRONTEND_URL') . '/' . $page->path;
161-
},
162156
```
163157

164158
### Overwriting models and resources
@@ -267,6 +261,78 @@ php artisan vendor:publish --provider="Outl1ne\PageManager\ToolServiceProvider"
267261

268262
You can add your translations to `resources/lang/vendor/nova-page-manager/` by creating a new translations file with the locale name (ie `et.json`) and copying the JSON from the existing `en.json`.
269263

264+
## Example of route and controller to serve pages
265+
266+
In routes/web.php
267+
```php
268+
Route::get('/page/{path?}', [PageController::class, 'show'])
269+
->where('path', '[\w-]+');
270+
```
271+
272+
In the controller
273+
```php
274+
public function show(Request $request, $path = '/')
275+
{
276+
277+
// Get the current locale
278+
$locale = App::getLocale();
279+
$locales = NPM::getLocales();
280+
281+
// Force a valid locale
282+
if (!isset($locales[$locale])) {
283+
$locale = array_key_first($locales);
284+
}
285+
286+
// get page model class
287+
$pageModel = NPM::getPageModel();
288+
289+
// get the model istance
290+
$page = $pageModel::where('active', true)
291+
->where(function($query) use ($locales, $path) {
292+
foreach($locales as $locale => $name){
293+
$query->orWhere('slug->' . $locale, $path);
294+
}
295+
})
296+
->first();
297+
298+
// return 404 if page not found
299+
if (!$page) {
300+
abort(404);
301+
}
302+
303+
// Get the page template
304+
$templateSlug = $page->template;
305+
306+
307+
// Prepare page data
308+
// maybe here you should filter the data by the locale
309+
$pageData = $page->toArray();
310+
311+
// Render the dynamic page component
312+
return Inertia::render('DynamicPage', [
313+
'page' => $pageData,
314+
'template' => $templateSlug,
315+
//maybe here you're interested also in regions
316+
//'regions' => NPM::getRegions(),
317+
]);
318+
319+
//OR
320+
321+
// return view('page', [
322+
// 'page' => $pageData,
323+
// 'template' => $templateSlug,
324+
// ]);
325+
326+
//OR
327+
328+
// return view('page.' . $templateSlug, [
329+
// 'page' => $pageData,
330+
// ]);
331+
332+
// ...
333+
}
334+
```
335+
270336
## Credits
271337

272338
- [Tarvo Reinpalu](https://github.com/Tarpsvo)

composer.json

Lines changed: 77 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,81 @@
11
{
2-
"name": "outl1ne/nova-page-manager",
3-
"description": "Page(s) and region(s) manager for Laravel Nova.",
4-
"keywords": [
5-
"laravel",
6-
"nova",
7-
"page",
8-
"manager"
9-
],
10-
"authors": [
11-
{
12-
"name": "Tarvo Reinpalu",
13-
"email": "[email protected]",
14-
"role": "Developer"
2+
"name": "outl1ne/nova-page-manager",
3+
"description": "Page(s) and region(s) manager for Laravel Nova.",
4+
"keywords": [
5+
"laravel",
6+
"nova",
7+
"page",
8+
"manager"
9+
],
10+
"authors": [
11+
{
12+
"name": "Tarvo Reinpalu",
13+
"email": "[email protected]",
14+
"role": "Developer"
15+
},
16+
{
17+
"name": "Outl1ne",
18+
"email": "[email protected]",
19+
"role": "Maintainer"
20+
}
21+
],
22+
"license": "MIT",
23+
"require": {
24+
"php": ">=8.0",
25+
"laravel/nova": "^5.0",
26+
"outl1ne/nova-translatable": "^3.0",
27+
"outl1ne/nova-translations-loader": "^5.0",
28+
"outl1ne/nova-multiselect-filter": "^5.0.1"
1529
},
16-
{
17-
"name": "Outl1ne",
18-
"email": "[email protected]",
19-
"role": "Maintainer"
20-
}
21-
],
22-
"license": "MIT",
23-
"require": {
24-
"php": ">=8.0",
25-
"laravel/nova": "^4.13",
26-
"outl1ne/nova-translatable": "^2.0.4",
27-
"outl1ne/nova-translations-loader": "^5.0",
28-
"outl1ne/nova-multiselect-filter": "^4.0.2"
29-
},
30-
"autoload": {
31-
"psr-4": {
32-
"Outl1ne\\PageManager\\": "src/"
30+
"autoload": {
31+
"psr-4": {
32+
"Outl1ne\\PageManager\\": "src/"
33+
},
34+
"files": []
3335
},
34-
"files": []
35-
},
36-
"extra": {
37-
"laravel": {
38-
"providers": [
39-
"Outl1ne\\PageManager\\NPMServiceProvider"
40-
],
41-
"aliases": {
42-
"NPMCache": "Outl1ne\\PageManager\\Facades\\NPMCache"
43-
}
44-
}
45-
},
46-
"config": {
47-
"sort-packages": true
48-
},
49-
"minimum-stability": "dev",
50-
"prefer-stable": true,
51-
"repositories": [
52-
{
53-
"type": "composer",
54-
"url": "https://nova.laravel.com"
36+
"extra": {
37+
"laravel": {
38+
"providers": [
39+
"Outl1ne\\PageManager\\NPMServiceProvider"
40+
],
41+
"aliases": {
42+
"NPMCache": "Outl1ne\\PageManager\\Facades\\NPMCache"
43+
}
44+
}
45+
},
46+
"config": {
47+
"sort-packages": true
48+
},
49+
"minimum-stability": "dev",
50+
"prefer-stable": true,
51+
"repositories": [
52+
{
53+
"type": "composer",
54+
"url": "https://nova.laravel.com"
55+
}
56+
],
57+
"require-dev": {
58+
"laravel/nova-devtool": "^1.8"
59+
},
60+
"autoload-dev": {
61+
"psr-4": {
62+
"Workbench\\App\\": "workbench/app/",
63+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
64+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
65+
}
66+
},
67+
"scripts": {
68+
"post-autoload-dump": [
69+
"@clear",
70+
"@prepare"
71+
],
72+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
73+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
74+
"build": "@php vendor/bin/testbench workbench:build --ansi",
75+
"serve": [
76+
"Composer\\Config::disableProcessTimeout",
77+
"@build",
78+
"@php vendor/bin/testbench serve --ansi"
79+
]
5580
}
56-
]
57-
}
81+
}

config/nova-page-manager.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@
9393
| Base URL
9494
|--------------------------------------------------------------------------
9595
|
96-
| Define the base URL for your pages. Can be a string (ie https://webshop.com)
97-
| or a closure.
98-
|
99-
| If a closure is specified, the function is called with the $page as a
100-
| parameter. For example: fn($page) => config('app.url') . $page->path;
96+
| Define the base URL for your pages. Must be serializable values like a string (ie https://webshop.com)
10197
|
10298
*/
10399

0 commit comments

Comments
 (0)