Models

Set your fillables to prevent mass-assignement. This is very important, as we use request()->all() in the module controller.

For fields that should default as null in the database when not sent by the form, use the nullable array.

For fields that should default to false in the database when not sent by the form, use the checkboxes array.

Depending upon the Twill features you need on your model, include the related traits and configure their respective options:

HasPosition

Implement the A17\Twill\Models\Behaviors\Sortable interface and add a position field to your fillables.

HasTranslation

Add translated fields in the translatedAttributes array.

Twill's HasTranslation trait is a wrapper around the popular astronomic/laravel-translatable package. A default configuration will be automatically published to your config directory when you run the twill:install command.

To setup your list of available languages for translated fields, modify the locales array in config/translatable.php, using ISO 639-1 two-letter languages codes as in the following example:

1<?php
2 
3return [
4 'locales' => [
5 'en',
6 'fr',
7 ],
8 ...
9];

HasSlug

Specify the field(s) used to create the slug in the slugAttributes array.

HasMedias

Add the mediasParams configuration array:

1<?php
2 
3public $mediasParams = [
4 'cover' => [ // role name
5 'default' => [ // crop name
6 [
7 'name' => 'default', // ratio name, same as crop name if single
8 'ratio' => 16 / 9, // ratio as a fraction or number
9 ],
10 ],
11 'mobile' => [
12 [
13 'name' => 'landscape', // ratio name, multiple allowed
14 'ratio' => 16 / 9,
15 ],
16 [
17 'name' => 'portrait', // ratio name, multiple allowed
18 'ratio' => 3 / 4,
19 ],
20 ],
21 ],
22 '...' => [ // another role
23 ... // with crops
24 ]
25];

HasFiles:

Add the filesParams configuration array:

1<?php
2 
3public $filesParams = ['file_role', ...]; // a list of file roles

HasRevisions

If you want you can limit the amount of revisions that are stored in the database by specifying a property on you model:

1class Author extends Model implements Sortable
2{
3 public int $limitRevisions = 5;
4}

You can also set a global revisions limit using by setting TwillConfig::maxRevisions

Scheduling

Also see Migrations documentation.

If the database for you model has the fields publish_start_date and publish_end_date you need to make those fillable to allow content scheduling.

In addition to them being fillable you also need to add the following casts:

1public $casts = [
2 'publish_start_date' => 'datetime',
3 'publish_end_date' => 'datetime'
4];