Download the PHP package weremagine/laravel-traits without Composer
On this page you can find all versions of the php package weremagine/laravel-traits. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download weremagine/laravel-traits
More information about weremagine/laravel-traits
Files in weremagine/laravel-traits
Package laravel-traits
Short Description A collection of opinionated Traits for use with Laravel.
License MIT
Informations about the package laravel-traits
Laravel Traits
A collection of opinionated traits for Laravel, by REMAGINE.
composer require weremagine/laravel-traits
TOC
- HasCreator
- HasImages
- HasOne
- HasSlug
- HasUniqueKey
- HasUuid
- UserAgent
HasCreator
HasCreator
automatically adds the current authorised user's id
to the user_id
column on record creation of models that implement it.
Usage
HasImages
HasImages
automatically appends images on retrieval of models that implement it.
imagesArray
function *required
A multidimensional array containing:
attribute
: the attribute name to append to the model.field
: the model field that contains the image path.
imagePrefix
function (optional)
The string to prefix all appended attributes with. If omitted, the field specified will be returned as it is stored.
Usage
HasOne
HasOne
automatically adds a differing related model relationship, where
$has_one_attribute
property (optional)
The name to use when setting the relationship, defaults to model
.
$has_one_type
property (optional)
The name of the field that contains the path to related model class, such as the value App\Models\Menu
- defaults to model_type
.
$has_one_id
property (optional)
The name of the field that contains the related model's id - defaults to model_id
.
Usage
HasSlug
HasSlug
automatically sets a slug when saving (creating or updating) any models that implement it.
$sluggify
property (optional)
The field name to use when creating the slug - defaults to name
.
Usage
HasUniqueKey
HasUniqueKey
automatically sets a unique key when creating records for models that implement it.
$unique_key
property (optional)
The field name to use when creating the unique key - defaults to key
.
$unique_key_length
property (optional)
The length you wish for the unique key to be - defaults to 10
.
$uppercase_key
property (optional)
A boolean to indicate if keys should be in uppercase - defaults to false
.
$key_prefix
property (optional)
The prefix for the unique key. - defaults to null
.
$key_suffix
property (optional)
The suffix for the unique key. - defaults to null
.
Usage
HasUuid
HasUuid
automatically sets a uuid when creating records for models that implement it.
$uuid_field
property (optional)
The field name to use when creating the uuid - defaults to uuid
.
Usage
Methods
byUuid
Retrieves a record using it's UUID.
UserAgent
UserAgent
automatically adds the user-agent
header specified in the request to an agent
field when new records of a model are stored.
$parse_agent_fields
property (optional)
A boolean to indicate whether or not to parse the agent string and store on creation - defaults to false
.
The following fields (nullable strings) are stored:
- platform
- platform_version
- browser
- browser_version
- device
- device_name