# Model structure

All your models live under the app directory.

A model is a representation of a database table, for example the Product model represents the products table.

To create a new model, run:

php tea make:model name=Product

Your model will look like this:

<?php

namespace App;

use Devlob\Database\Goku\Model;

class Product extends Model
{
}
1
2
3
4
5
6
7
8
9

# Change default table name

Tea will take the name of the class, convert it to lower case letters and then pluralize it in order to match it with the database table, in the example above Product corresponds to the products table.

If you need to override that, then you can manually pass the database table:

<?php

namespace App\Models;

use Devlob\Database\Goku\Model;

class Product extends Model
{
    protected static $table = 'products_table';
}
1
2
3
4
5
6
7
8
9
10

# Change default key for operations

By default id is used for operations, such as searching.

If you need to override that, then you can manually pass the key:

<?php

namespace App\Models;

use Devlob\Database\Goku\Model;

class Product extends Model
{
    protected static $key = 'slug';
}
1
2
3
4
5
6
7
8
9
10

# Accessors

In a model you can define accessors like this:

public function getFullNameAttribute()
{
    return "$this->first_name $this->last_name";
}
1
2
3
4

Then you can access that full name attribute anywhere in your application like this:

$user->full_name or $user->fullName