Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/dotcms-laravel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ DOTCMS_API_TOKEN=your-api-key-here

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

### Using Local SDK Development Setup

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:

1. First, ensure you're in the Laravel example directory:
```bash
cd examples/dotcms-laravel
```

2. If you have previously run `composer install`, remove the vendor directory:
```bash
rm -rf vendor
```

3. Install dependencies using the development configuration:
```bash
COMPOSER=composer.dev.json composer install
```

This will use the local SDK from the parent directory instead of the published package version.

## Configuration

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.
Expand Down
24 changes: 23 additions & 1 deletion examples/dotcms-laravel/app/Http/Controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,30 @@ public function index(Request $request)
$path = $request->path();
$path = $path === '/' ? '/' : '/' . $path;

// Get query parameters
$languageId = $request->query('language_id');
$mode = $request->query('mode');
$publishDate = $request->query('publishDate');
$personaId = $request->query('personaId');

// Create a page request for the current path
$pageRequest = $this->dotCMSClient->createPageRequest($path, 'json');

// Add query parameters if they exist
if ($languageId) {
$pageRequest = $pageRequest->withLanguageId((int)$languageId);
}
if ($mode) {
$pageRequest = $pageRequest->withMode($mode);
}
if ($personaId) {
$pageRequest = $pageRequest->withPersonaId($personaId);
}

if ($publishDate) {
$pageRequest = $pageRequest->withPublishDate($publishDate);
}

// Get the page data
$pageAsset = $this->dotCMSClient->getPage($pageRequest);

Expand Down Expand Up @@ -65,7 +86,8 @@ public function index(Request $request)
// Pass the data to the view
return view('page', [
'pageAsset' => $page,
'navigation' => $nav
'navigation' => $nav,
'publishDate' => $publishDate
]);
} catch (\Exception $e) {
// Log the error
Expand Down
81 changes: 81 additions & 0 deletions examples/dotcms-laravel/composer.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"$schema": "https://getcomposer.org/schema.json",
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": [
"laravel",
"framework"
],
"license": "MIT",
"repositories": [
{
"type": "path",
"url": "../../"
}
],
"require": {
"php": "^8.2",
"dotcms/php-sdk": "dev-main",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1"
},
"require-dev": {
"fakerphp/faker": "^1.23",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.13",
"laravel/sail": "^1.41",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpunit/phpunit": "^11.5.3"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
"@php artisan migrate --graceful --ansi"
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"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"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
Loading