Skip to content

Commit b5fc44f

Browse files
authored
Merge pull request #8 from dotCMS/fix-params-from-uve
Pass the query params from UVE to the page request
2 parents d58dca8 + 37ec4cb commit b5fc44f

File tree

15 files changed

+19987
-20
lines changed

15 files changed

+19987
-20
lines changed

examples/dotcms-laravel/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ DOTCMS_API_KEY=your-api-key-here
8080

8181
These environment variables define the connection to your DotCMS instance, allowing the SDK to authenticate and make API calls.
8282

83+
### Using Local SDK Development Setup
84+
85+
If you want to test the Laravel example with a local version of the PHP SDK (for development or testing new changes), you can use the `composer.dev.json` configuration:
86+
87+
1. First, ensure you're in the Laravel example directory:
88+
```bash
89+
cd examples/dotcms-laravel
90+
```
91+
92+
2. If you have previously run `composer install`, remove the vendor directory:
93+
```bash
94+
rm -rf vendor
95+
```
96+
97+
3. Install dependencies using the development configuration:
98+
```bash
99+
COMPOSER=composer.dev.json composer install
100+
```
101+
102+
This will use the local SDK from the parent directory instead of the published package version.
103+
83104
## Configuration
84105

85106
All the configuration described below is already implemented in this example project. The following sections explain the key components and how they work together to integrate DotCMS with Laravel.

examples/dotcms-laravel/app/Http/Controllers/AppController.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,30 @@ public function index(Request $request)
3434
$path = $request->path();
3535
$path = $path === '/' ? '/' : '/' . $path;
3636

37+
// Get query parameters
38+
$languageId = $request->query('language_id');
39+
$mode = $request->query('mode');
40+
$publishDate = $request->query('publishDate');
41+
$personaId = $request->query('personaId');
42+
3743
// Create a page request for the current path
3844
$pageRequest = $this->dotCMSClient->createPageRequest($path, 'json');
3945

46+
// Add query parameters if they exist
47+
if ($languageId) {
48+
$pageRequest = $pageRequest->withLanguageId((int)$languageId);
49+
}
50+
if ($mode) {
51+
$pageRequest = $pageRequest->withMode($mode);
52+
}
53+
if ($personaId) {
54+
$pageRequest = $pageRequest->withPersonaId($personaId);
55+
}
56+
57+
if ($publishDate) {
58+
$pageRequest = $pageRequest->withPublishDate($publishDate);
59+
}
60+
4061
// Get the page data
4162
$pageAsset = $this->dotCMSClient->getPage($pageRequest);
4263

@@ -65,7 +86,8 @@ public function index(Request $request)
6586
// Pass the data to the view
6687
return view('page', [
6788
'pageAsset' => $page,
68-
'navigation' => $nav
89+
'navigation' => $nav,
90+
'publishDate' => $publishDate
6991
]);
7092
} catch (\Exception $e) {
7193
// Log the error
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"$schema": "https://getcomposer.org/schema.json",
3+
"name": "laravel/laravel",
4+
"type": "project",
5+
"description": "The skeleton application for the Laravel framework.",
6+
"keywords": [
7+
"laravel",
8+
"framework"
9+
],
10+
"license": "MIT",
11+
"repositories": [
12+
{
13+
"type": "path",
14+
"url": "../../"
15+
}
16+
],
17+
"require": {
18+
"php": "^8.2",
19+
"dotcms/php-sdk": "dev-main",
20+
"laravel/framework": "^12.0",
21+
"laravel/tinker": "^2.10.1"
22+
},
23+
"require-dev": {
24+
"fakerphp/faker": "^1.23",
25+
"laravel/pail": "^1.2.2",
26+
"laravel/pint": "^1.13",
27+
"laravel/sail": "^1.41",
28+
"mockery/mockery": "^1.6",
29+
"nunomaduro/collision": "^8.6",
30+
"phpunit/phpunit": "^11.5.3"
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"App\\": "app/",
35+
"Database\\Factories\\": "database/factories/",
36+
"Database\\Seeders\\": "database/seeders/"
37+
}
38+
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"Tests\\": "tests/"
42+
}
43+
},
44+
"scripts": {
45+
"post-autoload-dump": [
46+
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
47+
"@php artisan package:discover --ansi"
48+
],
49+
"post-update-cmd": [
50+
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
51+
],
52+
"post-root-package-install": [
53+
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
54+
],
55+
"post-create-project-cmd": [
56+
"@php artisan key:generate --ansi",
57+
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
58+
"@php artisan migrate --graceful --ansi"
59+
],
60+
"dev": [
61+
"Composer\\Config::disableProcessTimeout",
62+
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite"
63+
]
64+
},
65+
"extra": {
66+
"laravel": {
67+
"dont-discover": []
68+
}
69+
},
70+
"config": {
71+
"optimize-autoloader": true,
72+
"preferred-install": "dist",
73+
"sort-packages": true,
74+
"allow-plugins": {
75+
"pestphp/pest-plugin": true,
76+
"php-http/discovery": true
77+
}
78+
},
79+
"minimum-stability": "stable",
80+
"prefer-stable": true
81+
}

0 commit comments

Comments
 (0)