### Install Twill Quickstart Starter Kit
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Runs the Twill installation command with the 'basic-page-builder' argument to set up a pre-configured quickstart project.
```Bash
php artisan twill:install basic-page-builder
```
--------------------------------
### Starting Laravel Development Server
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/2_installing-laravel.md
Run the built-in Artisan command to start a local development server, making the Laravel application accessible via a web browser.
```Shell
php artisan serve
```
--------------------------------
### Install Twill Basic Page Builder Example
Source: https://github.com/area17/twill/blob/3.x/examples/basic-page-builder/README.md
Runs the Twill Artisan command to install the 'basic-page-builder' example into the current Laravel project.
```Shell
php artisan twill:install basic-page-builder
```
--------------------------------
### Setup Twill API Docs Environment (Shell)
Source: https://github.com/area17/twill/blob/3.x/docs-api/README.md
Navigates into the documentation directory and installs project dependencies using Composer.
```Shell
cd docs-api
composer install
```
--------------------------------
### Initializing Git Repository and First Commit
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/2_installing-laravel.md
Initialize a new Git repository in the project root, add all current files to the staging area, and create the initial commit to track the project's history.
```Shell
git init
```
```Shell
git add .
```
```Shell
git commit -m "Initial commit"
```
--------------------------------
### Navigating into Project Directory
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/2_installing-laravel.md
Change the current directory in the terminal to the root of the newly created Laravel project.
```Shell
cd laravel-twill
```
--------------------------------
### Run Standard Twill Installation
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Executes the main Twill installation process, which includes setting up routes, migrations, configuration, assets, and prompting for a superadmin user.
```Bash
php artisan twill:install
```
--------------------------------
### Creating New Laravel Project with Composer
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/2_installing-laravel.md
Use Composer's create-project command to download and set up a new Laravel application in a specified directory (e.g., 'laravel-twill'). This command fetches all necessary dependencies.
```Shell
composer create-project laravel/laravel laravel-twill
```
--------------------------------
### Configuring Application URL in .env
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/2_installing-laravel.md
Set the APP_URL variable in the project's .env file to match the local development URL where the application is being served.
```Env
APP_URL=http://laravel-twill.test
```
--------------------------------
### Install Frontend Dependencies and Build Assets
Source: https://github.com/area17/twill/blob/3.x/examples/basic-page-builder/README.md
Installs Node.js dependencies listed in package.json using npm and then runs the build script to compile frontend assets like CSS.
```Shell
npm install
```
```Shell
npm run build
```
--------------------------------
### Example Twill Module Controller Setup (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/5_controllers.md
Demonstrates how to set up a Twill module controller by extending `ModuleController`. The `setUpController` method is used to configure various options, such as enabling the display of images in the content list.
```php
enableShowImage();
}
}
```
--------------------------------
### Local Package Installation Instructions (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/14_packages/1_creating-a-package.md
This is the example output provided by the package generation command. It shows how to add the locally generated package to your project's composer.json repositories and then require it using composer.
```bash
Your package has been generated!
You can now add it to your project's composer json repositories to work on it:
"repositories": [
{
"type": "path",
"url": "./packages/twill-extension"
},
],
Then you can require it: composer require area17/twill-extension
By default the package has no functionality, you can add a first capsule using (Replace YourModel with the model you want to use):
php artisan twill:make:capsule YourModel --singleton --packageDirectory=./packages/twill-extension --packageNamespace=TwillExtension\\YourModel
Enjoy!
```
--------------------------------
### Install Laravel Project
Source: https://github.com/area17/twill/blob/3.x/examples/basic-page-builder/README.md
Uses Composer to create a new Laravel project in a specified directory and then navigates into that directory.
```Shell
composer create-project laravel/laravel laravel-twill
```
```Shell
cd laravel-twill
```
--------------------------------
### Add Admin Subdomain to Hosts File
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Example entry for the /etc/hosts file to map an admin subdomain to the local development IP address, required for accessing the admin panel via subdomain in some environments.
```Hosts File
# this is an example, use your own IP and domain
192.168.10.10 domain.test
192.168.10.10 admin.domain.test
```
--------------------------------
### Defining Twill Module Routes - PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/4_navigation.md
Provides an example of how to structure your routes using the `TwillRoutes` facade and `Route::group` to correspond with the navigation structure. This routing setup is essential for both the OOP and Legacy navigation methods to ensure proper linking and automatic active state highlighting in the Twill UI.
```php
'work'], function () {
Route::group(['prefix' => 'projects'], function () {
TwillRoutes::module('projectCustomers');
});
TwillRoutes::module('projects');
TwillRoutes::module('clients');
TwillRoutes::module('industries');
TwillRoutes::module('studios');
});
```
--------------------------------
### Installing Laravel Localization
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/2_building_a_multilingual_site_with_twill_and_laravel_localization.md
Install the Laravel Localization package using Composer. This command downloads the package and its dependencies into your project.
```bash
composer require mcamara/laravel-localization
```
--------------------------------
### Installing Twill Capsules via Artisan
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/4_capsules.md
Use the `twill:capsule:install` Artisan command to install existing capsules from sources like GitHub. Options like `--copy` and `--require` determine the installation strategy. The `--branch` option can specify a branch.
```Shell
php artisan twill:capsule:install
```
```Shell
php artisan twill:capsule:install area17/twill-capsule-redirections --copy --branch=main
```
--------------------------------
### Run Twill Installation Command
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/3_installing-twill.md
Executes the Twill Artisan command to finalize the installation process. This command handles database migrations, publishes necessary assets and configuration files, and prompts for the creation of the initial super administrator user.
```Shell
php artisan twill:install
```
--------------------------------
### Configure Custom Admin Subdomain Example
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Another example of setting the ADMIN_APP_URL environment variable to specify a custom subdomain, such as 'manage.domain.test', for accessing the Twill admin console.
```Environment Variables
ADMIN_APP_URL=http://manage.domain.test
```
--------------------------------
### Run Laravel Development Server
Source: https://github.com/area17/twill/blob/3.x/examples/basic-page-builder/README.md
Starts Laravel's built-in development server, useful when a local web server environment is not available.
```Shell
php artisan serve
```
--------------------------------
### Serve Twill API Documentation Locally (Shell)
Source: https://github.com/area17/twill/blob/3.x/docs-api/README.md
Runs the Composer script to start a local web server for accessing the generated documentation.
```Shell
composer run serve
```
--------------------------------
### Accessing Twill Settings (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/8_settings-sections/1_index.md
Provides examples of how to retrieve settings values using the `TwillAppSettings` facade. Demonstrates getting translated, non-translated, full block data, and the block service object based on group, section, and field names.
```php
TwillAppSettings::getTranslated('site-settings.copyright.left_text'); // Get a translatable setting in the current locale.
TwillAppSettings::get('site-settings.copyright.year'); // Get a non-translatable setting.
TwillAppSettings::getGroupDataForSectionAndName('site-settings', 'copyright'); // Get the full `block` model for the settings.
TwillAppSettings::getBlockServiceForGroupAndSection('site-settings', 'copyright'); // Get the full block object, this is especially useful if you have a block editor in the settings, and you need to render those.
```
--------------------------------
### Install Twill Package with Composer
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Installs the core Twill package into your Laravel project using Composer. Specifies version 3.4.
```Bash
composer require area17/twill:"^3.4"
```
--------------------------------
### Link Storage Directory
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Creates a symbolic link from the public directory to the storage directory, necessary for serving user-uploaded files.
```Bash
php artisan storage:link
```
--------------------------------
### Running Migrations After Capsule Installation
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/4_capsules.md
After installing and configuring a capsule, run the `php artisan migrate` command to apply any database migrations included with the capsule.
```Shell
php artisan migrate
```
--------------------------------
### Install Twill CMS (Artisan, PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/16_artisan-commands/index.md
Generates and runs core migrations for a starter Twill installation. Automatically creates a superadmin user after migration. Running this command multiple times can cause errors.
```PHP
php artisan twill:install {preset? : Optional, the preset to install} {--fromBuild}
```
--------------------------------
### Install PHP_CodeSniffer Globally (Shell)
Source: https://github.com/area17/twill/blob/3.x/CONTRIBUTING.md
Installs the PHP_CodeSniffer tool globally using Composer. This is a prerequisite for using the phpcs VS Code extension for PHP contextual linting.
```Shell
composer global require "squizlabs/php_codesniffer=*"
```
--------------------------------
### Enable Strict Admin Domain Handling
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Sets the environment variable ADMIN_APP_STRICT to 'true' to enforce that the admin panel is only accessible when the domain matches the APP_URL configuration.
```Environment Variables
ADMIN_APP_STRICT=true
```
--------------------------------
### Configure Twill Admin Subdomain
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Sets the environment variable ADMIN_APP_URL to specify a full URL, typically used to serve the Twill admin console from a subdomain like 'admin.domain.test'.
```Environment Variables
ADMIN_APP_URL=http://admin.domain.test
```
--------------------------------
### Configure Imgix Image Service Environment Variables (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Defines the environment variables needed to configure Twill to use Imgix for rendering responsive images. This assumes you have configured an Imgix source pointing to your Twill uploads bucket.
```bash
MEDIA_LIBRARY_IMAGE_SERVICE="A17\Twill\Services\MediaLibrary\Imgix"
IMGIX_SOURCE_HOST=source.imgix.net
```
--------------------------------
### Configure Twill Options Using TwillConfig Facade
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
Demonstrates how to set configuration options using the `TwillConfig` facade within your application's service provider (e.g., `AppServiceProvider`). This example sets the maximum number of revisions for revisionable content.
```php
...
use A17\Twill\Facades\TwillConfig;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
TwillConfig::maxRevisions(5);
}
}
```
--------------------------------
### Registering Single Settings Group (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/8_settings-sections/1_index.md
Demonstrates how to register a single settings group with Twill using the `TwillAppSettings` facade within the `boot` method of a service provider. Includes setting name, label, and an example access control closure.
```php
use A17\Twill\Facades\TwillAppSettings;
public function boot(): void
{
TwillAppSettings::registerSettingsGroup(
SettingsGroup::make()
->name('site-settings')
->label('Site settings')
->availableWhen(fn() => \Auth::user()->can('manage.settings')) // Example access control.
);
}
```
--------------------------------
### Starting Twill development mode for Sail/Docker users
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/4_creating_custom_components_form_fields_and_blocks.md
Provides a workaround command for Sail/Docker environments to start the Twill development server by explicitly setting the `SHELL` environment variable before running `twill:dev`.
```Bash
export SHELL=/usr/bin/bash && php artisan twill:dev
```
--------------------------------
### Require Twill Package with Composer
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/3_installing-twill.md
Installs the Twill Laravel package version 3.4 or higher using Composer, along with its dependencies, making the core Twill code available in the project.
```Shell
composer require area17/twill:"^3.4"
```
--------------------------------
### Starting Twill development mode with hot reloading
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/4_creating_custom_components_form_fields_and_blocks.md
Executes the Twill Artisan command to start the development server, enabling hot reloading and auto-refresh for faster development of custom components.
```Bash
php artisan twill:dev
```
--------------------------------
### Hydrating Model for Revisions Preview in Twill Repository (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/11_repositories.md
Shows how to implement the `hydrate` method, typically used to prepare a model instance for previewing revisions by hydrating relationships or specific fields. It includes examples of using helper methods like `hydrateBrowser`, `hydrateMultiSelect`, and `hydrateRepeater`. It requires calling the parent method.
```php
hydrateBrowser($object, $fields, 'relationName');
// or a multiselect
$this->hydrateMultiSelect($object, $fields, 'relationName');
// or a repeater
$this->hydrateRepeater($object, $fields, 'relationName');
return parent::hydrate($object, $fields);
}
```
--------------------------------
### Casting Scheduling Dates (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/10_models.md
Example of adding casts for `publish_start_date` and `publish_end_date` to ensure they are treated as datetime objects, required for content scheduling functionality.
```php
public $casts = [
'publish_start_date' => 'datetime',
'publish_end_date' => 'datetime'
];
```
--------------------------------
### Configuring HasMedias Params (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/10_models.md
Example configuration for the `$mediasParams` array, defining roles, crops, and ratios for media attachments on the model when using the `HasMedias` trait.
```php
[ // role name
'default' => [ // crop name
[
'name' => 'default', // ratio name, same as crop name if single
'ratio' => 16 / 9, // ratio as a fraction or number
],
],
'mobile' => [
[
'name' => 'landscape', // ratio name, multiple allowed
'ratio' => 16 / 9,
],
[
'name' => 'portrait', // ratio name, multiple allowed
'ratio' => 3 / 4,
],
],
],
'...' => [ // another role
... // with crops
]
];
```
--------------------------------
### Configure Twill Admin Path
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Sets the environment variable ADMIN_APP_PATH to change the URL path for the Twill admin console from the default '/admin' to a custom path like '/cms'.
```Environment Variables
ADMIN_APP_PATH=/cms
```
--------------------------------
### Configure S3 Storage Environment Variables (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Defines the essential environment variables required to configure Twill to use S3-compatible storage for uploads. Ensure your S3 bucket's CORS policy allows requests from your CMS domain.
```bash
S3_KEY=
S3_SECRET=
S3_BUCKET=
S3_REGION=
```
--------------------------------
### Generating Twill Block Component (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/02_creating-a-block-editor.md
Provides examples of the Artisan command used to generate a new Twill Block component class. The command supports different formats for specifying the component name and namespace.
```php
php artisan twill:make:componentBlock Namespace/Name
php artisan twill:make:componentBlock namespace.name
php artisan twill:make:componentBlock name
```
--------------------------------
### Install Rector for Twill 3.0.0 Upgrade (Bash)
Source: https://github.com/area17/twill/blob/3.x/UPGRADE.md
Installs the Rector dependency via Composer as a development requirement. Rector is used in the upgrade process from 3.0.0-rc4 to 3.0.0 to automatically update configuration files.
```bash
composer require rector/rector --dev
```
--------------------------------
### Configure VS Code Prettier Formatter (JSON)
Source: https://github.com/area17/twill/blob/3.x/CONTRIBUTING.md
Sets Visual Studio Code to format files on save using the Prettier extension as the default formatter. Requires the Prettier VS Code extension to be installed.
```JSON
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
```
--------------------------------
### Installing Vue Numeric Dependency via npm
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/4_creating_custom_components_form_fields_and_blocks.md
This command installs the `vue-numeric` package from the npm registry. This package is required as a dependency for implementing a custom numeric form field component in Vue.js, as demonstrated in a later example (not shown here).
```Shell
npm install vue-numeric --save
```
--------------------------------
### Configure Twill Admin Subdomain in .env
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/3_installing-twill.md
Sets the ADMIN_APP_URL environment variable in the .env file to configure Twill to be accessible via a specific subdomain (e.g., admin.yourdomain.com) instead of the default /admin path.
```dotenv
ADMIN_APP_URL=admin.laravel-twill.test
```
--------------------------------
### Configure Azure Blob Storage Environment Variables (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Defines the essential environment variables required to configure Twill to use Azure Blob Storage for uploads. Ensure your Blob Storage container's CORS policy allows requests from your CMS domain.
```bash
AZURE_ACCOUNT_KEY=
AZURE_ACCOUNT_NAME=
```
--------------------------------
### Removed Twill Migration Helper Functions (PHP)
Source: https://github.com/area17/twill/blob/3.x/UPGRADE.md
Shows the source code for the `twillIncrementsMethod` and `twillIntegerMethod` helper functions, which were removed in Twill 3.x. These functions conditionally determined the appropriate schema builder method based on a configuration setting.
```php
if (!function_exists('twillIncrementsMethod')) {
/**
* @return string
*/
function twillIncrementsMethod()
{
return config('twill.migrations_use_big_integers')
? 'bigIncrements'
: 'increments';
}
}
if (!function_exists('twillIntegerMethod')) {
/**
* @return string
*/
function twillIntegerMethod()
{
return config('twill.migrations_use_big_integers')
? 'bigInteger'
: 'integer';
}
}
```
--------------------------------
### Implementing Filtering in Twill Repository (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/11_repositories.md
Demonstrates how to implement the `filter` method in a Twill repository to customize query filtering. It shows examples of using built-in helper methods like `addLikeFilterScope`, `searchIn`, and `addRelationFilterScope`, as well as manual query manipulation. It emphasizes calling the parent method.
```php
addLikeFilterScope($query, $scopes, 'field_in_scope');
// add orWhereHas clauses
$this->searchIn($query, $scopes, 'field_in_scope', ['field1', 'field2', 'field3']);
// add a whereHas clause
$this->addRelationFilterScope($query, $scopes, 'field_in_scope', 'relationName');
// or just go manually with the $query object
if (isset($scopes['field_in_scope'])) {
$query->orWhereHas('relationName', function ($query) use ($scopes) {
$query->where('field', getLikeOperator(), '%' . $scopes['field_in_scope'] . '%');
});
}
// don't forget to call the parent filter function
return parent::filter($query, $scopes);
}
```
--------------------------------
### Serve Twill Static Docs (Shell)
Source: https://github.com/area17/twill/blob/3.x/docs/readme.md
This command compiles and serves the Twill documentation site locally. It typically makes the documentation available at http://localhost:8000/.
```Shell
./vendor/bin/testbench twill:staticdocs:serve
```
--------------------------------
### Twill Block Preview Layout Blade File
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/06_previewing-blocks.md
Example of the required Blade layout file (`resources/views/site/layouts/block.blade.php`) needed to enable individual block previews in the Twill editor. This layout acts as a wrapper for the block content and should include necessary frontend assets and a `@yield('content')` directive.
```Blade
#madewithtwill website
@yield('content')
```
--------------------------------
### Customizing Form Fields in Twill Repository (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/11_repositories.md
Illustrates how to implement the `getFormFields` method to add or modify form fields associated with a model in the Twill admin panel. It includes examples of getting fields for browsers and repeaters using helper methods and returning the combined fields. It requires calling the parent method first.
```php
getFormFieldsForBrowser($object, 'relationName');
// get fields for a repeater
$fields = $this->getFormFieldsForRepeater($object, $fields, 'relationName', 'ModelName', 'repeaterItemName');
// return fields
return $fields;
}
```
--------------------------------
### Implement Homepage Display Logic (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/10_setup-the-frontpage.md
Adds a `home` method to the `PageDisplayController`. This method retrieves the selected homepage page from the Twill application settings (`homepage.homepage.page`). It checks if a page is selected and published, and if so, renders the `site.page` view with the selected page data; otherwise, it aborts with a 404 error.
```PHP
forSlug($slug);
if (!$page) {
abort(404);
}
return view('site.page', ['item' => $page]);
}
public function home(): View
{
if (TwillAppSettings::get('homepage.homepage.page')->isNotEmpty()) {
/** @var \App\Models\Page $frontPage */
$frontPage = TwillAppSettings::get('homepage.homepage.page')->first();
if ($frontPage->published) {
return view('site.page', ['item' => $frontPage]);
}
}
abort(404);
}
}
```
--------------------------------
### Visiting Twill Admin Panel (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/15_testing/index.md
Shows how to use the `visitTwill` macro on a Dusk browser instance to navigate directly to the Twill administration dashboard.
```PHP
$this->browse(function(Browser $browser) {
$browser->visitTwill();// [tl! focus]
});
```
--------------------------------
### Run Twill Automated Upgrade Script (Bash)
Source: https://github.com/area17/twill/blob/3.x/UPGRADE.md
Executes the official Twill upgrade script provided within the vendor package. This script automates many common upgrade tasks like namespace changes, file renames, and compatibility fixes.
```bash
php ./vendor/area17/twill/upgrade.php
```
--------------------------------
### Output of Twill Module Creation Help Command
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/4_creating-the-page-module.md
Shows the detailed usage, arguments, and options provided by the `php artisan twill:make:module --help` command. It lists flags for features like blocks, translation, slugs, medias, files, position, revisions, nesting, blade forms, preview generation, parent models, and an 'all' option.
```shell
$ php artisan twill:make:module --help
Description:
Create a new Twill Module
Usage:
twill:make:module [options] [--]
Arguments:
moduleName
Options:
-B, --hasBlocks
-T, --hasTranslation
-S, --hasSlug
-M, --hasMedias
-F, --hasFiles
-P, --hasPosition
-R, --hasRevisions
-N, --hasNesting
--bladeForm
-E, --generatePreview
--parentModel[=PARENTMODEL]
--all
```
--------------------------------
### Defining News Index Route with Localization (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/2_building_a_multilingual_site_with_twill_and_laravel_localization.md
Sets up the `/news` route using Laravel's routing and localization middleware. It fetches published articles, orders them by creation date, and passes them to the `site.articles.index` view.
```php
use App\Models\Article;
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localize', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath'],
], function () {
Route::get('news', function () {
return view('site.articles.index', [
'articles' => Article::published()->orderBy('created_at', 'desc')->get(),
]);
})->name('articles');
});
```
--------------------------------
### Build Twill Static Docs Fresh (Shell)
Source: https://github.com/area17/twill/blob/3.x/docs/readme.md
This command generates the static documentation files from scratch, ignoring previous builds. It is useful when layout or structure changes have been made to ensure a complete rebuild.
```Shell
./vendor/bin/testbench twill:staticdocs:generate --fresh
```
--------------------------------
### Enabling Installed Capsule in config/twill.php
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/4_capsules.md
After installing a capsule, you need to enable it in your `config/twill.php` file by adding an entry to the `capsules.list` array. The `name` should match the capsule's identifier, and `enabled` should be set to `true`.
```PHP
[
'list' => [
[
'name' => 'Redirections',
'enabled' => true,
],
],
],
...
];
```
--------------------------------
### Build Twill Static Docs (Shell)
Source: https://github.com/area17/twill/blob/3.x/docs/readme.md
This command generates the static files for the Twill documentation. This is used to create the final output for deployment.
```Shell
./vendor/bin/testbench twill:staticdocs:generate
```
--------------------------------
### Adding Installed Capsule to Navigation in config/twill-navigation.php
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/4_capsules.md
To make an installed capsule accessible in the Twill admin navigation, add an entry to your `config/twill-navigation.php` file. The key should be the capsule's identifier, and `module` should be set to `true`.
```PHP
return [
'redirections' => [
'title' => 'Redirections',
'module' => true,
],
];
```
--------------------------------
### Example Filters Method Implementation Twill PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/6_table-builder.md
This example demonstrates a typical implementation of the `filters()` method, showcasing how to instantiate `TableFilters` and add various filter types like `BelongsToFilter`, `FieldSelectFilter`, `BooleanFilter`, and a custom `BasicFilter`.
```PHP
public function filters(): TableFilters
{
return TableFilters::make([
BelongsToFilter::make()->field('partner'),
FieldSelectFilter::make()->field('year'),
BooleanFilter::make()->field('published')->label('Published'),
BasicFilter::make()
->queryString('verified')
->options(collect(['yes' => 'Verified', 'no' => 'Not verified']))
->apply(function (Builder $builder, string $value) {
if ($value === 'yes') {
$builder->where('is_verified', true);
} elseif ($value === 'no') {
$builder->where('is_verified', false);
}
}),
]);
}
```
--------------------------------
### Forcing NPM install during Twill asset build
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/4_creating_custom_components_form_fields_and_blocks.md
Executes the Twill Artisan command to build project assets, explicitly forcing the installation of Twill's NPM dependencies before building.
```Bash
php artisan twill:build --install
```
--------------------------------
### Listing Available Twill Icons (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/02_creating-a-block-editor.md
This command runs the `twill:list:icons` Artisan command. It displays a list of all icons that are available for use with Twill blocks, repeaters, and other components. This helps developers choose appropriate icons for their custom elements.
```Shell
php artisan twill:list:icons
```
--------------------------------
### Create Article References Block (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/7_prefill-block-editor-from-template.md
Generates the necessary files for a new Twill block named 'article-references' using the Artisan command.
```Artisan
php artisan twill:make:block article-references
```
--------------------------------
### Example: Adding Opengraph Fieldset to Twill Form (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/7_form-builder.md
Provides a concrete example of adding a fieldset named 'Opengraph' using `addFieldset`, including common fields like title, description, and image using `Input::make()` and `Files::make()`.
```php
$form->addFieldset(
Fieldset::make()->title('Opengraph')->id('opengraph')->fields([
Input::make()->name('og_title')->label('OG Title'),
Input::make()->name('og_description')->label('OG Description'),
Files::make()->name('og_image')->label('OG Image')
])
);
```
--------------------------------
### Require Twill Dependency
Source: https://github.com/area17/twill/blob/3.x/examples/basic-page-builder/README.md
Adds the specified version of the Area 17 Twill package to the project's dependencies using Composer.
```Shell
composer require area17/twill:"^3.2"
```
--------------------------------
### AWS IAM Policy for Imgix S3 Read Access
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/7_media-library/07_imgix-tips.md
This JSON policy grants an AWS IAM user read-only permissions required by Imgix to access objects within a specified S3 bucket. It includes actions for getting objects, listing the bucket contents, and getting the bucket's location.
```json
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::YOUR_BUCKET_IDENTIFIER/*",
"arn:aws:s3:::YOUR_BUCKET_IDENTIFIER"
]
}
]
}
```
--------------------------------
### Viewing Help for Twill Module Creation Command
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/4_creating-the-page-module.md
Displays the available options and arguments for the `twill:make:module` Artisan command. This helps users understand how to customize the module generation process.
```shell
php artisan twill:make:module --help
```
--------------------------------
### Visiting Twill Module Entry (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/15_testing/index.md
Shows how to use `visitModuleEntryWithTitle` to navigate to the edit page of an existing entry for a specified module ('Partners') identified by its title ('Twill'). Requires visiting Twill first.
```PHP
$this->browse(function(Browser $browser) {
$browser->visitTwill();
$browser->visitModuleEntryWithTitle('Partners', 'Twill');// [tl! focus]
});
```
--------------------------------
### Creating Twill Module (bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/6_manage_frontend_user_profiles_from_twill.md
Generates the necessary files for a new Twill module named 'Profiles' using the Twill Artisan command. This is the first step in setting up the module to manage user profiles.
```bash
php artisan twill:make:module Profiles
```
--------------------------------
### Configuring HasFiles Params (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/10_models.md
Example configuration for the `$filesParams` array, specifying a list of file roles allowed for the model when using the `HasFiles` trait.
```php
browse(function(Browser $browser) {
$browser->visitTwill();
$browser->createModuleEntryWithTitle('Partners', 'Twill');// [tl! focus]
});
```
--------------------------------
### Configuring Translatable Locales (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/10_models.md
Example configuration for the `locales` array in `config/translatable.php`, specifying the available languages for translated fields using ISO 639-1 codes.
```php
[
'en',
'fr',
],
...
];
```
--------------------------------
### Configure Session Domain for Subdomains
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/2_installation.md
Sets the environment variable SESSION_DOMAIN to allow sharing cookies between the main domain and subdomains, useful for features like draft previews.
```Environment Variables
SESSION_DOMAIN=.domain.test
```
--------------------------------
### Configure Twill Imgix Service and Source Host (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
Sets environment variables to enable the Imgix image service in Twill and specify the Imgix source host URL. This is the initial step to integrate Imgix for image processing.
```bash
MEDIA_LIBRARY_IMAGE_SERVICE="A17\Twill\Services\MediaLibrary\Imgix"
IMGIX_SOURCE_HOST=source.imgix.net
```
--------------------------------
### Publishing Laravel Localization Configuration
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/2_building_a_multilingual_site_with_twill_and_laravel_localization.md
Publish the configuration file for the Laravel Localization package. This command copies the default configuration file to your application's config directory, allowing you to customize its settings.
```bash
php artisan vendor:publish --provider="Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider"
```
--------------------------------
### Authenticating User for Twill Dusk (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/15_testing/index.md
Demonstrates how to create a superadmin user via Artisan and then log in as that user within a Dusk browser instance using the `loginAs` helper with the `twill_users` guard.
```PHP
$this->artisan('twill:superadmin user@example.org password');
$this->browse(function(Browser $browser) {
$browser->loginAs(\App\Models\User::firstWhere('email', 'user@example.org'), 'twill_users');
});
```
--------------------------------
### Configuring Twill Local Image Rendering Service (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
Sets environment variables to configure Twill to use the local Glide image rendering service instead of a third-party service like Imgix. This is the default configuration.
```bash
MEDIA_LIBRARY_ENDPOINT_TYPE=local
MEDIA_LIBRARY_IMAGE_SERVICE="A17\Twill\Services\MediaLibrary\Glide"
```
--------------------------------
### Implementing BelongsToFilter Twill PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/6_table-builder.md
The `BelongsToFilter` creates a select filter based on a BelongsTo relationship, using the titles of the related models as options. This example filters by a 'partner' relationship.
```PHP
BelongsToFilter::make()->field('partner');
```
--------------------------------
### Limiting HasRevisions Count (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/10_models.md
Example of setting the `$limitRevisions` property on a model to control the maximum number of revisions stored in the database for that specific model when using the `HasRevisions` trait.
```php
class Author extends Model implements Sortable
{
public int $limitRevisions = 5;
}
```
--------------------------------
### Create Article Header Block (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/7_prefill-block-editor-from-template.md
Generates the necessary files for a new Twill block named 'article-header' using the Artisan command.
```Artisan
php artisan twill:make:block article-header
```
--------------------------------
### Implementing BooleanFilter Twill PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/6_table-builder.md
The `BooleanFilter` is designed for simple true/false filtering based on a model field. This example shows how to create a boolean filter for a 'published' field with a custom label.
```PHP
BooleanFilter::make()->field('published')->label('Published');
```
--------------------------------
### Adding Color Column to Database Table (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/4_form-fields/13_color.md
Provides a database migration example to add a nullable string column named 'main_color' with a length of 10 to a table, suitable for storing color values.
```php
Schema::table('posts', function (Blueprint $table) {
...
$table->string('main_color', 10)->nullable();
...
});
```
--------------------------------
### Interacting Within New Twill Editor Block (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/15_testing/index.md
Illustrates using `withinNewBlock` to add a block ('Text') and execute a callback function that receives the browser instance and a field prefix, allowing manual typing into block fields like `type($prefix . '[title][en]', 'Hello world')`. Requires visiting a module entry page.
```PHP
$this->browse(function(Browser $browser) {
$browser->visitTwill();
$browser->visitModuleEntryWithTitle('Partners', 'Twill');
$browser->withinNewBlock('Text', function(Browser $browser, string $prefix) { // [tl! focus:start]
$browser->type($prefix . '[title][en]', 'Hello world');
});// [tl! focus:end]
$browser->pressSaveAndCheckSaved('Save as draft');
});
```
--------------------------------
### Override Specific Enabled Twill Feature
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
Demonstrates how to override a single feature setting in the `config/twill.php` file without including the entire default `enabled` array. This example shows how to disable the dashboard feature.
```php
[
'dashboard' => false,
],
];
```
--------------------------------
### Registering Twill Navigation (OOP Method) - PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/4_navigation.md
Demonstrates how to programmatically define Twill admin navigation within the `boot` method of your `AppServiceProvider` using the `TwillNavigation` facade and `NavigationLink` components. It shows how to add primary links and nest children to create secondary and tertiary navigation levels.
```php
use A17\Twill\Facades\TwillNavigation;
use A17\Twill\View\Components\Navigation\NavigationLink;
public function boot(): void
{
TwillNavigation::addLink(
NavigationLink::make()->forModule('pages')
);
TwillNavigation::addLink(
NavigationLink::make()->forModule('projects')
->setChildren([
NavigationLink::make()->forModule('projects')
->setChildren([
NavigationLink::make()->forModule('projectCustomers'),
]),
NavigationLink::make()->forModule('clients'),
NavigationLink::make()->forModule('industries'),
NavigationLink::make()->forModule('studios'),
]),
);
}
```
--------------------------------
### Generate Twill API Documentation (Shell)
Source: https://github.com/area17/twill/blob/3.x/docs-api/README.md
Executes the Composer script defined to build the API documentation using Doctum.
```Shell
composer run build
```
--------------------------------
### Twill Non-Translatable Field Grouping Setup - PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/4_form-fields/16_field-grouping.md
Shows the database migration and model fillable attributes needed to set up a non-translatable grouped field stored in a JSON column in Twill.
```php
## Add a migration
Schema::table('blogs', function (Blueprint $table) {
$table->json('external_link')->nullable();
});
## Update your models fillable
class Blog extends Model {
protected $fillable = [
...
'external_link'
];
}
```
--------------------------------
### Configure Twill UI Locales
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
These options in `config/twill.php` allow setting the default and fallback locales for the Twill administration panel UI. This example sets the default locale to French (`fr`) and the fallback to English (`en`).
```php
return [
'locale' => 'fr',
'fallback_locale' => 'en',
];
```
--------------------------------
### Getting Image URL (Blade)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/02_creating-a-block-editor.md
Demonstrates how to generate an image URL for a block image field within the Blade view using the `$image` helper function, specifying the role, crop, and optional parameters.
```blade
{{ $image('cover', 'default', ['h' => 100) }}
```
--------------------------------
### Defining Image Crops (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/02_creating-a-block-editor.md
Demonstrates how to define image crop configurations directly within the Block component class using the `getCrops` static method. This allows specifying different crop ratios and minimum dimensions for block images.
```php
public static function getCrops(): array
{
return [
'content_image' => [
'default' => [
[
'name' => 'default',
'ratio' => 16 / 9,
'minValues' => [
'width' => 100,
'height' => 100,
],
],
]
]
];
}
```
--------------------------------
### Create Linked Article Block (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/7_prefill-block-editor-from-template.md
Generates the necessary files for a new Twill block named 'linked-article' using the Artisan command.
```Artisan
php artisan twill:make:block linked-article
```
--------------------------------
### Set Twill Application Names per Subdomain (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
This PHP configuration array shows how to define custom application names for each subdomain used in Twill's multi-subdomain setup, which can be displayed in the CMS interface.
```php
[
'subdomain1' => 'App 1 name',
'subdomain2' => 'App 2 name',
],
];
```
--------------------------------
### Create Article Paragraph Block (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/7_prefill-block-editor-from-template.md
Generates the necessary files for a new Twill block named 'article-paragraph' using the Artisan command.
```Artisan
php artisan twill:make:block article-paragraph
```
--------------------------------
### Adding Block Editor Field (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/02_creating-a-block-editor.md
Adds the Twill block editor field to a module form using the FormBuilder. The first example shows the basic field, and the second specifies which block types are allowed.
```php
BlockEditor::make()
BlockEditor::make()
->blocks(['title', 'quote', 'text'])
```
--------------------------------
### Configure Twill Media Library for S3-Compatible Storage (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
These environment variables configure Twill's media library to use an S3-compatible storage service (like Minio), requiring the access key, secret key, bucket name, and the custom endpoint URL.
```bash
S3_KEY=S3_KEY
S3_SECRET=S3_SECRET
S3_BUCKET=bucket-name
S3_ENDPOINT=https://YOUR_S3_DOMAIN
```
--------------------------------
### Example Map Data Structure
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/4_form-fields/14_map.md
Illustrates the structure of the data stored in the database for the map field, showing both the default format (lat/lng, address) and the extended format (including types and bounding box) when saveExtendedData is enabled.
```json
{
"latlng": "48.85661400000001|2.3522219",
"address": "Paris, France"
}
```
```json
{
"latlng": "51.1808302|-2.256022799999999",
"address": "Warminster BA12 7LG, United Kingdom",
"types": [
"point_of_interest",
"establishment"
],
"boundingBox": {
"east": -2.25289275,
"west": -2.257066149999999,
"north": 51.18158853029149,
"south": 51.17889056970849
}
}
```
--------------------------------
### Update Root Route for Homepage (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/10_setup-the-frontpage.md
Modifies the `routes/web.php` file to replace the default closure-based route for the root URL (`/`) with a new route that points to the `home` method of the `PageDisplayController`. It also keeps the route for displaying other pages by slug.
```PHP
Route::get('/', function () { // [tl! --]
return view('welcome'); // [tl! --]
}); // [tl! --]
Route::get('/', [\App\Http\Controllers\PageDisplayController::class, 'home'])->name('frontend.home'); // [tl! ++]
Route::get('{slug}', [\App\Http\Controllers\PageDisplayController::class, 'show'])->name('frontend.page');
```
--------------------------------
### Adding Image Column Before Title in Twill Table PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/3_modules/6_table-builder.md
Provides an example of manipulating the `TableColumns` collection obtained from the parent method to insert a new column (an Image column for 'cover') at a specific position (before the title).
```php
protected function getIndexTableColumns(): TableColumns
{
$table = parent::getIndexTableColumns();
$after = $table->splice(1);
$table->push(
Image::make()->field('cover')
);
return $table->merge($after);
}
```
--------------------------------
### Creating a Translatable Twill Module
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/2_building_a_multilingual_site_with_twill_and_laravel_localization.md
Use the Twill Artisan command to generate a new module with support for translations (-T) and slugs (-S). This command creates the necessary files for an 'articles' module.
```bash
php artisan twill:make:module -TS articles
```
--------------------------------
### Get Template Label Attribute (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/7_prefill-block-editor-from-template.md
Defines an accessor method on the `Article` model to retrieve the human-readable label for the currently selected template value. It searches the `AVAILABLE_TEMPLATES` array by the 'value' property.
```PHP
public function getTemplateLabelAttribute()\n{\n $template = collect(static::AVAILABLE_TEMPLATES)->firstWhere('value', $this->template);\n\n return $template['label'] ?? '';\n}
```
--------------------------------
### Creating a Twill Block from a Base Template (Artisan)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/5_block-editor/02_creating-a-block-editor.md
This command uses the `twill:make:block` Artisan command to generate a new block file. It creates a block named `ExceptionalMedia` based on the existing `media` block template, and specifies `image` as the default icon. The new file will be located in `views/twill/blocks`.
```Shell
$ php artisan twill:make:block ExceptionalMedia media image
```
--------------------------------
### Rendering Nested Block Editor in Settings (Blade)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/8_settings-sections/1_index.md
Shows how to render content from a nested block editor field within a settings section. It uses the `getBlockServiceForGroupAndSection` method to get the block object and then renders its children.
```blade
{!! \TwillAppSettings::getBlockServiceForGroupAndSection('site-settings','text')->renderData->renderChildren('default') !!}
```
--------------------------------
### Twill Translatable Field Grouping Setup - PHP
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/4_form-fields/16_field-grouping.md
Demonstrates the database migration, model fillable attributes, and model casts required to set up a translatable grouped field stored in a JSON column in Twill.
```php
## Add a migration
Schema::table('blog_translations', function (Blueprint $table) {
$table->json('external_link')->nullable();
});
## Update your models fillable
class Blog extends Model {
public $translatedAttributes = [
...
'external_link'
];
protected $fillable = [
...
'external_link'
];
}
## Update your Translation model and add the cast
public $casts = [
'external_link' => 'array',
];
```
--------------------------------
### Configure Twill Media Library for Local Storage (Bash)
Source: https://github.com/area17/twill/blob/3.x/docs/content/1_docs/2_getting-started/3_configuration.md
These environment variables configure Twill's media library to use the local filesystem for storage, specifying the endpoint type and the directory path for uploads.
```bash
MEDIA_LIBRARY_ENDPOINT_TYPE=local
MEDIA_LIBRARY_LOCAL_PATH=uploads
```
--------------------------------
### Define Homepage Settings View (Blade)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/10_setup-the-frontpage.md
Creates a Blade view file for the 'homepage' settings group. It uses Twill block directives (`@twillBlockTitle`, `@twillBlockIcon`, `@twillBlockGroup`) and a `` component to provide a UI element for selecting a 'pages' module item, which will be stored under the name 'page'.
```Blade
@twillBlockTitle('Homepage')
@twillBlockIcon('text')
@twillBlockGroup('app')
```
--------------------------------
### Register Homepage Settings Group (PHP)
Source: https://github.com/area17/twill/blob/3.x/docs/content/2_guides/1_page-builder-with-blade/10_setup-the-frontpage.md
Registers a new settings group named 'homepage' with the label 'Homepage' using `TwillAppSettings::registerSettingsGroup` within the `boot` method of the `AppServiceProvider`. This makes the settings section available in the Twill backend.
```PHP
forModule('pages')
);
TwillNavigation::addLink(
NavigationLink::make()->forModule('menuLinks')->title('Menu')
);
TwillAppSettings::registerSettingsGroup(
SettingsGroup::make()->name('homepage')->label('Homepage')
);
}
}
```