v3
Config Generator

Config Generator

Craftable PRO provides a powerful YAML-based configuration system that allows you to quickly generate whole CRUD including multiple models, routes, controllers, views etc. from single YAML file.

💡

YAML config files are also generated when using CRUD generator command

Configuration Structure

The configuration file is built around models. You can define multiple models in one file. For each model you can define the following:

table

The name of the table in the database. For example posts.

skip_model

If set to true, the model class will not be generated or overwritten if exists.

columns

Database columns definition. This use common syntax with Laravel Blueprint. Please refer to official Blueprint docs (opens in a new tab) to see all definitions.

listing

List of columns that should be displayed in the listing table. The order will be preserved and used in the table.

You can add sortable to allow sorting by the column.

You can add searchable to allow search by the column.

form

List of fields that will be used for edit/create form. Fields need to be defined inside cards and columns. This is because the form can have multi column layout, where every column can have multiple cards (visual group of fields).

Refer to the example YAML config file bellow to see the exact structure.

translatable

List of fields, that should be translatable. For these fields, you will be able to use translations by Spatie's Laravel Translatable package (opens in a new tab).

publishable

Name of the field, that will be used for publishing functionality. Special form field and listing column will be generated for publishable field.

media_collections

List of media collections, using Spatie's Laravel Medialibrary (opens in a new tab).

You can add isImage to collection to define image collection.

relationships

List of relationships you want to define on the model. You can define belongsTo or belongsToMany relationships.

api

List of API endpoints. You can generate following endpoints:

  • index
  • store
  • update
  • show
  • destroy

Every endpoint except destroy requires you to define columns, which is list of fields that will be returned from the enpoint (for GET requests) or be accepted by the endpoint (for POST/PUT requests).

If you want to skip generation of specific endpoint, simply exclude it from the config file.

features

List of additional features that will be generated. Right now, we support following features:

  • export: will generate excel export

Example YAML config file

craftable-pro:
    models:
        Post:
            table: posts
            skip_model: false
            columns:
                id: id
                title: string
                body: string
                translatable_field: json
                published_at: 'datetime nullable'
                created_at: 'datetime nullable'
                updated_at: 'datetime nullable'
            listing:
                id: 'sortable searchable'
                title: 'sortable searchable'
                published_at: sortable
                created_at: sortable
            form:
                columns:
                    -
                        cards:
                            -
                                fields:
                                    - title
                                    - body
                                    - translatable_field
                    -
                        cards:
                            -
                                fields:
                                    - published_at
            translatable:
                - translatable_field
            publishable: published_at
            media_collections:
                - cover: isImage
                - gallery: isImage
            relationships: {  }
            api:
                index:
                    columns:
                        - id
                        - title
                        - body
                        - translatable_field
                        - published_at
                        - created_at
                        - updated_at
                store:
                    columns:
                        - title
                        - body
                        - translatable_field
                        - published_at
                update:
                    columns:
                        - title
                        - body
                        - translatable_field
                        - published_at
                show:
                    columns:
                        - id
                        - title
                        - body
                        - translatable_field
                        - published_at
                        - created_at
                        - updated_at
                destroy: {  }
            features:
                - export

Using pre-made YAML configs

Since you can define the whole CRUD in one YAML file, it is really easy to share the config files between the projects. We are right now preparing a set of shareable YAML files that you can use to generate the whole app like CRM or Blog. These YAML configs will be published soon on craftable.pro (opens in a new tab).

Last updated on December 20, 2024