Skip to content
On this page

Fillable

By default, using Quick Models or Custom Models, Larawiz won't add as $fillable attributes that are:

  • a timestamp,
  • a boolean,
  • a relation,
  • a soft delete column,
  • a column that contains the word token,
  • or a primary key.

Larawiz considers these attributes as app-dependant, which saves you more keystrokes and expanding the lifetime of your keyboard, tablet or phone.

yaml
models:
  # ...

  Post:
    title: string
    slug: string
    body: longText
    published_at: timestamp nullable
    is_commentable: boolean default:true
    user: belongsTo
    softDeletes: ~
1
2
3
4
5
6
7
8
9
10
11
php
class Post extends Model
{
    protected $fillable = ['title', 'slug', 'body'];

    // ...
}
1
2
3
4
5
6

Timestamps are NOT fillable. Period.

Note that the published_at wasn't included in the $fillable array because is a timestamp. If you want it fillable, you can always use datetime, date or time, but be wary of the query constraints on these column types.

yaml
models:
  Post:
    # ...
    publised_at: datetime nullable
1
2
3
4

php
class Post extends Model
{
    protected $fillable = [
        // ...
        'published_at'
    ];
}
1
2
3
4
5
6
7

Overriding the fillable attributes

To override the fillable attributes, use the fillable key with the list of fillable properties. Larawiz won't check if the fillable attribute exist, so you can go full manual.

In this example, we will set the title, body and published_at columns for the Model, since we plan to automatically create the slug from the title itself after we receive our scaffolded app, and the published_at will allow to publish something into the future.

yaml
models:
  Post:
    title: string
    slug: string
    body: longText
    published_at: timestamp nullable
    user: belongsTo
    softDeletes: ~
      
    fillable:
      - title
      - body
      - published_at
1
2
3
4
5
6
7
8
9
10
11
12
13
php
class Post extends Model
{
    protected $fillable = ['title', 'body', 'published_at'];

    // ...
}
1
2
3
4
5
6

No fillable attributes

If you have no plans to have fillable attributes, you can set the fillable property to false.

yaml
models:
  Post:
    title: string
    slug: string
    body: longText
    published_at: timestamp nullable
    user: belongsTo
    softDeletes: ~
      
    fillable: false
1
2
3
4
5
6
7
8
9
10