In this section · 4 articles

Generate a resource with the Scaffolder

Describe a new list-and-form screen (its module, name and fields), preview every file the generator would write, then write them from the screen or with the matching command.

Applies to
Stub Generator 1.0 and later
Who can do this
Developer
Permission
feature.stubgen.scaffolder.generate
Where
Scaffolder (Platform Administration)
On this page

A resource is one kind of record in a module, with its list, form and detail screens, permissions, menu entry and tests. The Scaffolder screen builds all of it from a short description, using the same generator as Core's php artisan laramin:make-resource command.

Danger: Generate writes files into the code of the Laramin you're signed in to, on its server. Use it only on a development copy that's under version control, never on your live Laramin. Review the files and commit them like any other code change.

Before you start

  • The module must already exist in Modules/. To start one, see Create a new module shell.
  • You need Use Scaffolder (feature.stubgen.scaffolder.view) to open the screen and preview. Writing files also needs Generate Scaffold (feature.stubgen.scaffolder.generate). Without it, the Generate button isn't shown and you can only preview.
  • The web server must be able to write to the module's folder.

Steps

  1. In the Platform Administration sidebar, select Scaffolder. The Vue CRUD Scaffolder screen opens in Resource mode.

  2. Under Blueprint, fill in:

    • Module: the module's folder name, such as Inventory.
    • Entity: the record's name, singular, such as Item.
    • Abbreviation: optional. The module's permission abbreviation, used in permission keys such as feature.inv.item.list. Leave it empty to use the module's own.
  3. Set the switches: Soft deletes, Gated (policy), Read-only and Factory. The first two are on to start with. See Scaffolder fields, options and generated files.

  4. Under Fields, describe each field. A title field is already there.

    1. Select Add field.

    2. Enter its Name in lowercase, with underscores, such as unit_price.

    3. Choose its Type.

    4. For a belongsTo field, enter the Related model. For a select field, enter its Options, separated by commas.

    5. Tick Nullable or Unique if needed. Open Advanced to choose where the field appears and whether it can be searched, sorted or filtered.

      Scaffolder Fields section with a unit_price decimal field set to Nullable and Unique, and its Advanced options highlighted: Searchable, Sortable, Filterable, Primary column, Translatable, On index, On form, On detail.
  5. Select Preview. The Preview card lists every file, with a count, and shows the contents of the file you choose under File.

    Vue CRUD Scaffolder in Resource mode with Module Inventory, Entity Item, the four switches and the title and unit_price fields. The Preview card shows 15 files and the Item model file's contents.
  6. Check the preview. Change the blueprint and select Preview again until it's right.

  7. To write the files, select Generate. To replace files that already exist, turn on Overwrite existing files first.

  8. In Generate files, select Generate.

    Generate files dialog asking to write the generated files into module Inventory, which creates files on disk, with Cancel and the Generate button highlighted.

The Result card shows Files generated successfully., or Generated with warnings — review the result below., with the number of files written and skipped. Existing files are skipped unless you chose to overwrite them. Each new PHP file is checked for syntax errors, and any are listed under Syntax errors in generated files.

Tip: You don't have to write from the screen. The line under the buttons, Preview only — write the files with the CLI:, shows the matching php artisan laramin:make-resource command for your blueprint. Run it on your development copy instead.

What happens next

The new screen doesn't appear until you finish the Next steps the Result card lists. Run these on the server, in your Laramin's folder:

  1. php artisan module:migrate Inventory, with your module's name, to create the table.
  2. php artisan permission:sync --module=Inventory --force to add the new permissions.
  3. php artisan optimize:clear.
  4. Add the menu entry. No command rebuilds the menu on its own; see The Scaffolder shows warnings, or what it made doesn't appear for how to add it.

Then give the new permissions to the roles that need them. See Give someone a role.

If it doesn't work

For warnings in the result, skipped files, or a screen that doesn't appear, see The Scaffolder shows warnings, or what it made doesn't appear.

  • "Module [Inventory] does not exist on disk." Create the module first, then generate the resource into it.
  • Preview or Generate can't be selected. Fill in Module and Entity, and give every field a name.
  • "Could not build the preview." The message under it names the problem, such as an unknown field type. Module and entity names must start with a letter and use only letters and digits. Field names must start with a lowercase letter and use only lowercase letters, digits and underscores.