simklee/laravel-crafting-table

Laravel Package to craft extended models.

v0.9.0.1 2022-02-18 10:39 UTC

This package is auto-updated.

Last update: 2024-12-18 18:59:23 UTC


README

This package provides several tools to build models, including the Repository Pattern, extended ModelQuery, API and CRUD.

Installation

Require this package with composer.

composer require simklee/laravel-crafting-table

Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

If you use this package as a dev requirement you have export some classes into your namespace:

php artisan crafter:install --dev 

Commands

Model Definitions

Each model is defined in the model configuration. You can export a sample configuration by publishing the configuration file from vendor:

php artisan vendor:publish --provider="SimKlee\LaravelCraftingTable\LaravelCraftingTableServiceProvider" --tag="config"

Published config file (`config/models.php`):

<?php
return [
    'Model' => [
        'table'      => '',
        'columns'    => [],
        'values'     => [],
        'defaults'   => [],
        'timestamps' => false,
        'softDelete' => false,
        'uuid'       => false,
        'factory'    => [],
        'samples'    => 0,
        'views'      => [
            'index'  => [],
            'edit'   => [],
            'create' => [],
            'show'   => [],
        ],
    ],
];

The model name is defined by the key. All parts of each model definition are listed bellow.

KeyDescription
tableThe table name of the model [string]. Usually the (snake cased) plural of the model name.
columnsA list of the columns of the model [array]. The used keywords to specify the column are documented bellow (see bellow).
valuesThe possible values of the columns [array]. <br/>Example: `'values' => ['col1' => ['val1', 'val2'], ...]`)
defaultsThe default values of the columns [array]. <br/>Example: 'defaults' => ['col1' => 'val1', ...]
timestampsDefines, if the model uses the timestamps feature of Laravel [boolean] (Laravel documentation).
softDeleteDefines, if the model uses the soft delete feature of Laravel [boolean] (Laravel documentation).
uuidDefines, if the model uses the timestamps feature of this package [boolean] (see bellow).
factoryDefines, which property of Faker to use for each column. [array] (see bellow).
samplesDefines, how many fake data sets will be generated. [int] (see bellow).
viewsDefines, which columns will be processed for each view. [array] (see bellow).

Columns

Each column can be specified by several keywords.

Examples:

Example DefinitionDescription
integer|unsigned|primary|autoincrement <br/>(short: int|unsigned|ai)A common definition of a primary key.
varchar|length:50A required column which stores a string up to 50 chars.
varchar|length:50|nullableAn optional column which stores a string up to 50 chars.

List of all data types:

Data Type KeywordsDescription
Numeric data typesEach date and time data type will be casted to int inside the model.
tinyinteger <br/>(short: tinyint)A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.
smallinteger <br/>(short: smallint)A small integer. The signed range is -32,768 to 32,767. The unsigned range is 0 to 65,535.
mediuminteger <br/>(short: mediumint)A medium-sized integer. The signed range is -8,388,608 to 8,388,607. The unsigned range is 0 to 16,777,215.
integer <br/>(short: int)A normal-size integer. The signed range is -2,147,483,648 to 2,147,483,647. The unsigned range is 0 to 4,294,967,295.
biginteger <br/>(short: bigint)A large integer. The signed range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The unsigned range is 0 to 18,446,744,073,709,551,615.
boolean <br/>(short: bool)These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true.
decimalA packed “exact” fixed-point number. The maximum number of digits for decimal is 65. The maximum number of supported decimals is 30.
floatA floating-point number.
Date and Time Data TypesEach date and time data type will be casted to Carbon object inside the model.
dateA date. The supported range is '1000-01-01' to '9999-12-31'. It is displayed in 'YYYY-MM-DD' format. Inside the model it is casted to .
datetimeA date and time combination. The supported range is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999'.
timestampA timestamp. The range is '1970-01-01 00:00:01.000000' UTC to '2038-01-19 03:14:07.999999' UTC. <br/>TIMESTAMP values are stored as the number of seconds since the epoch ('1970-01-01 00:00:00' UTC).
timeA time. The range is '-838:59:59.000000' to '838:59:59.000000'.
yearA year in 4-digit format.
StringString Data Types
varchar <br/>(short: string)Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. <br/>The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
charThe length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. <br/>(When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled.)
binaryThe BINARY type is similar to CHAR, except that it stores binary strings rather than non-binary strings. That is, they store byte strings rather than character strings. This means they have the binary character set and collation, and comparison and sorting are based on the numeric values of the bytes in the values.
varbinaryThe VARBINARY type is similar to VARCHAR, except that it stores binary strings rather than non-binary strings. That is, they store byte strings rather than character strings. This means they have the binary character set and collation, and comparison and sorting are based on the numeric values of the bytes in the values.
tinyblobA binary large object that can store 255 (2^8 - 1) bytes.
blobA binary large object that can store 65,535 (2^16 - 1) bytes (64 KB).
mediumblobA binary large object that can store 16,777,215 (2^24 - 1) bytes (16 MB).
longblobA binary large object that can store 4,294,967,295 (2^32 - 1) bytes (4 GB).
tinytextA non-binary string (character strings) up to 255 (2^8 - 1) bytes.
textA non-binary string (character strings) up to 65,535 (2^16 - 1) bytes (64 KB).
mediumtextA non-binary string (character strings) up to 16,777,215 (2^24 - 1) bytes (16 MB).
longtextA non-binary string (character strings) up to 4,294,967,295 (2^32 - 1) bytes (4 GB).

UUID Usage