# Generators

> make:control and make:perimeter scaffold the controls and the perimeter classes, from stubs that you can publish and change.

```bash
php artisan make:perimeter ClientPerimeter
php artisan make:perimeter EditorialPerimeter --hooks
php artisan make:control PostControl --model=Post --perimeters=ClientPerimeter --perimeters=EditorialPerimeter
php artisan make:control CommentControl --parent=post
```

## `make:control`

Writes a control into `app/Access/Controls`.

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --model
      </code>
      
      , <code>
        -m
      </code>
    </td>
    
    <td>
      The model of the control: <code>
        --model=Post
      </code>
      
       for <code>
        App\Models\Post
      </code>
      
      , or a fully qualified class such as <code>
        --model='Domain\Blog\Post'
      </code>
      
      . Without it, the model is named after the control: <code>
        App\Models\Post
      </code>
      
       for <code>
        PostControl
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --perimeters
      </code>
      
      , <code>
        -p
      </code>
    </td>
    
    <td>
      A perimeter class of <code>
        app/Access/Perimeters
      </code>
      
      , repeatable. The control gets an <code>
        allowed()
      </code>
      
      , <code>
        should()
      </code>
      
       and <code>
        query()
      </code>
      
       callback for each one, which refuse everything until you write them, except the callbacks of the hooks that the class overrides.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --parent
      </code>
    </td>
    
    <td>
      A <code>
        belongsTo
      </code>
      
       relation of the model, repeatable: writes a <a href="/essentials/parents">
        <code>
          ThroughParent
        </code>
      </a>
      
       entry for it.
    </td>
  </tr>
</tbody>
</table>

- The command refuses, and writes nothing, when the model is not an Eloquent model class.
- The perimeters are listed as loose perimeters, which add up: group the levels of a hierarchy in [`Levels::of()`](/essentials/levels) yourself.
- A perimeter class whose constructor requires arguments, or is not public, is left out with a warning: list it in the control with its named constructor.
- The control declares no boundary: add a [`boundary()`](/essentials/boundaries) method when the model needs one.

See [Controls](/essentials/controls#generating-a-control).

## `make:perimeter`

Writes a perimeter class into `app/Access/Perimeters`.

- Without option, the class is empty: its rules are the callbacks declared in the control.
- `--hooks` generates the protected hooks `allows()`, `includes()` and `scope()`, which refuse everything until you write them, for a rule shared by several controls. Remove `includes()` to check the rows in SQL.

See [Perimeter classes](/essentials/perimeter-classes).

## Stubs

Publish the stubs to change what the commands write:

```bash
php artisan stub:publish
```

<table>
<thead>
  <tr>
    <th>
      Stub
    </th>
    
    <th>
      Used by
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        stubs/control.stub
      </code>
    </td>
    
    <td>
      <code>
        make:control
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stubs/perimeter.plain.stub
      </code>
    </td>
    
    <td>
      <code>
        make:perimeter
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stubs/perimeter.hooks.stub
      </code>
    </td>
    
    <td>
      <code>
        make:perimeter --hooks
      </code>
    </td>
  </tr>
</tbody>
</table>

A published stub replaces the one of the package. After an upgrade, publish them again with `php artisan stub:publish --force`, or apply the changes of the package to your copies.
