PHPackages                             weremagine/laravel-traits - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. weremagine/laravel-traits

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

weremagine/laravel-traits
=========================

A collection of opinionated Traits for use with Laravel.

1.1.6(5y ago)0561MITPHP

Since May 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/weremagine/laravel-traits)[ Packagist](https://packagist.org/packages/weremagine/laravel-traits)[ RSS](/packages/weremagine-laravel-traits/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (15)Used By (0)

Laravel Traits
==============

[](#laravel-traits)

A collection of opinionated traits for Laravel, by **REMAGINE**.

`composer require weremagine/laravel-traits`

TOC
---

[](#toc)

- [HasCreator](#HasCreator)
- [HasImages](#HasImages)
- [HasOne](#HasOne)
- [HasSlug](#HasSlug)
- [HasUniqueKey](#HasUniqueKey)
- [HasUuid](#HasUuid)
- [UserAgent](#UserAgent)

HasCreator
----------

[](#hascreator)

`HasCreator` automatically adds the current authorised user's `id` to the `user_id` column on record creation of models that implement it.

### Usage

[](#usage)

```
use Remagine\Traits\HasCreator;

class Article extends Model
{
    use HasCreator;
```

HasImages
---------

[](#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

[](#usage-1)

```
use Remagine\Traits\HasImages;

class Article extends Model
{
    use HasImages;

    /**
     * Images to append to the model via HasImages.
     *
     * @return array
     */
    public function imagesArray()
    {
        return [
            [
                'attribute' => 'image_url',
                'field' => 'image',
            ],
        ];
    }

    /**
     * The string to prefix image attributes with.
     *
     * @returns string
     */
    public function imagePrefix()
    {
        return env('AWS_CDN').'/';
    }
```

HasOne
------

[](#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

[](#usage-2)

```
use Remagine\Traits\HasOne;

class QrCode extends Model
{
    use HasOne;

    /**
     * The name to give the relationship via the HasOne trait.
     *
     * @var string
     */
    protected $has_one_attribute = 'model';

    /**
     * The name of the field to lookup the HasOne model.
     *
     * @var string
     */
    protected $has_one_type = 'model_type';

    /**
     * The name of the field containing the HasOne model's id.
     *
     * @var string
     */
    protected $has_one_id = 'model_id';
```

HasSlug
-------

[](#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

[](#usage-3)

```
use Remagine\Traits\HasSlug;

class Article extends Model
{
    use HasSlug;

    /**
     * The attribute to sluggify when saving.
     *
     * @var string
     */
    protected $sluggify = 'title';
```

HasUniqueKey
------------

[](#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

[](#usage-4)

```
use Remagine\Traits\HasUniqueKey;

class Article extends Model
{
    use HasUniqueKey;

    /**
     * The name of the unique key for the model.
     */
    protected $unique_key = 'key';

    /**
     * The length unique keys generated should be.
     */
    protected $unique_key_length = 10;

    /**
     * Indicates if the key should be uppercased.
     */
    protected $uppercase_key = false;

    /**
     * The prefix for the unique key.
     */
    protected $key_prefix = null;

    /**
     * The suffix for the unique key.
     */
    protected $key_suffix = null;
```

HasUuid
-------

[](#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

[](#usage-5)

```
use Remagine\Traits\HasUuid;

class Article extends Model
{
    use HasUuid;

    /**
     * The name of the field to store uuids.
     */
    protected $uuid_field = 'uuid';
```

### Methods

[](#methods)

`byUuid`Retrieves a record using it's UUID.

```
Article::byUuid($uuid);
```

UserAgent
---------

[](#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

### Usage

[](#usage-6)

```
use Remagine\Traits\UserAgent;

class Article extends Model
{
    use UserAgent;

    /**
     * Indicates if the agent should be parsed when saving.
     *
     * @var array
     */
    protected $parse_agent_fields = false;
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 85.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Recently: every ~15 days

Total

14

Last Release

1877d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e03683d4ffe58fd94dcd679a0f880298dc005904d58c448654eb2ac5d3e6d263?d=identicon)[davidsneal](/maintainers/davidsneal)

---

Top Contributors

[![davidsneal](https://avatars.githubusercontent.com/u/6142131?v=4)](https://github.com/davidsneal "davidsneal (23 commits)")[![rdainton](https://avatars.githubusercontent.com/u/31499161?v=4)](https://github.com/rdainton "rdainton (4 commits)")

---

Tags

laraveltraits

### Embed Badge

![Health badge](/badges/weremagine-laravel-traits/health.svg)

```
[![Health](https://phpackages.com/badges/weremagine-laravel-traits/health.svg)](https://phpackages.com/packages/weremagine-laravel-traits)
```

###  Alternatives

[prevailexcel/laravel-action-service-trait

A simple Laravel package to create actions, traits and services using artisan commands

143.0k](/packages/prevailexcel-laravel-action-service-trait)[cleaniquecoders/shrinkr

Shrinkr is a Laravel package for shortening URLs, with custom slugs, analytics, branded domains, and seamless API integration.

142.9k](/packages/cleaniquecoders-shrinkr)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
