Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the creation of Sites with Builder #34

Merged
merged 3 commits into from
Oct 31, 2024
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
92 changes: 91 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Statamic Builder

The Statamic Builder speeds up building Statamic sites. It offers a clear method to define blueprints, fieldsets, collections, naviations and taxonomies using PHP classes. This approach enhances code readability and maintainability compared to writing YAML files.
The Statamic Builder speeds up building Statamic sites. It offers a clear method to define sites, blueprints, fieldsets, collections, naviations and taxonomies using PHP classes. This approach enhances code readability and maintainability compared to writing YAML files.

For example, you can define a collection blueprint as follows:

Expand Down Expand Up @@ -360,3 +360,93 @@ This addon enables you to define collections and taxonomies in PHP classes, simp
],
];
```

### How to create a Site

> [!WARNING]
The sites are cached forever. When adding a site, you need to clear the cache.

1. Create a new site by running the following command:

```bash
php artisan make:site Blog
```

2. Define your site in the generated file. For example:

```php
<?php

namespace App\Sites;

use Tdwesten\StatamicBuilder\BaseSite;

class Blog extends BaseSite
{
/**
* Return the handle for the site
*
* Example: return 'default';
*/
public function handle(): string
{
return 'blog';
}

/**
* Return the handle for the site
*
* Example: return 'Default';
*/
public function name(): string
{
return 'Blog';
}

/**
* Return the base url for the site
*
* Example: return '/';
*/
public function url(): string
{
return '/blog';
}

/**
* Return the locale of the site
*
* Example: return '/';
*/
public function locale(): string
{
return 'en_US';
}

/**
* Return the array of extra attributes for the site
*
* Example: return ['foo' => 'bar'];
*/
public function attributes(): array
{
return [];
}
}
```

3. Register the Site in your `config/statamic/builder.php` file:

```php
<?php
return [
'sites' => [
\App\Sites\Blog::class
],
];
```

4. Clear the cache:
```bash
php artisan cache:clear
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
"php": "^8.2",
"illuminate/support": "^10.0|^11.0",
"laravel/framework": "^10.0|^11.0",
"statamic/cms": "^4.46|^5.0"
"statamic/cms": "^5.0"
},
"require-dev": {
"pestphp/pest": "^2.33",
"laravel/pint": "^1.7",
"orchestra/testbench": "^8.0",
"spatie/laravel-ray": "^1.36",
"pestphp/pest-plugin-laravel": "^2.2",
"statamic/eloquent-driver": "^3.4"
"statamic/eloquent-driver": "^4.16"
},
"config": {
"allow-plugins": {
Expand Down
Loading
Loading