PHPackages                             vajexal/laravel-attributes-relationships - 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. [Database &amp; ORM](/categories/database)
4. /
5. vajexal/laravel-attributes-relationships

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

vajexal/laravel-attributes-relationships
========================================

Laravel eloquent relationships using attributes

0.1.0(4y ago)051UnlicensePHPPHP ^8.0

Since May 26Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vajexal/laravel-attributes-relationships)[ Packagist](https://packagist.org/packages/vajexal/laravel-attributes-relationships)[ RSS](/packages/vajexal-laravel-attributes-relationships/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Laravel eloquent relationships using php 8 attributes

[![Build Status](https://github.com/vajexal/laravel-attributes-relationships/workflows/Build/badge.svg)](https://github.com/vajexal/laravel-attributes-relationships/actions)[![codecov](https://camo.githubusercontent.com/b8b87382f3d594d91825a64b8667a6c3ee95cdccd14205e36de6c4ea3fac9507/68747470733a2f2f636f6465636f762e696f2f67682f76616a6578616c2f6c61726176656c2d617474726962757465732d72656c6174696f6e73686970732f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d45434f315042424f5934)](https://codecov.io/gh/vajexal/laravel-attributes-relationships)

### Installation

[](#installation)

```
composer require vajexal/laravel-attributes-relationships
```

The package will automatically register a service provider

### Usage

[](#usage)

#### One To One

[](#one-to-one)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\HasOne;

#[HasOne(Phone::class)]
class User extends Model
{
}

// ...

User::first()->phone;
```

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\BelongsTo;

#[BelongsTo(User::class)]
class Phone extends Model
{
}

// ...

Phone::first()->user;
```

#### One To Many

[](#one-to-many)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\HasMany;

#[HasMany(Comment::class)]
class Post extends Model
{
}

// ...

Post::first()->comments;
```

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\BelongsTo;

#[BelongsTo(Post::class)]
class Comment extends Model
{
}

// ...

Comment::first()->post;
```

#### Many To Many

[](#many-to-many)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\BelongsToMany;

#[BelongsToMany(Role::class)]
class User extends Model
{
}

// ...

User::first()->roles;
```

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\BelongsToMany;

#[BelongsToMany(User::class)]
class Role extends Model
{
}

// ...

Role::first()->users;
```

#### Has One Through

[](#has-one-through)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\HasOneThrough;

#[HasOneThrough(Owner::class, Car::class)]
class Mechanic extends Model
{
}

// ...

// If you don't like method name, then you can define relation method
Mechanic::first()->owner;
```

#### Has Many Through

[](#has-many-through)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\HasManyThrough;

#[HasManyThrough(Post::class, User::class)]
class Country extends Model
{
}

// ...

Country::first()->posts;
```

#### One To One (Polymorphic)

[](#one-to-one-polymorphic)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\MorphOne;

#[MorphOne(Image::class, 'imageable')]
class User extends Model
{
}

// ...

User::first()->image;
```

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\MorphTo;

#[MorphTo('imageable')]
class Image extends Model
{
}

// ...

Image::first()->imageable;
```

#### One To Many (Polymorphic)

[](#one-to-many-polymorphic)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\MorphMany;

#[MorphMany(Image::class, 'imageable')]
class Post extends Model
{
}

// ...

Post::first()->images;
```

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\MorphTo;

#[MorphTo('imageable')]
class Image extends Model
{
}

// ...

Image::first()->imageable;
```

#### Many To Many (Polymorphic)

[](#many-to-many-polymorphic)

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\MorphToMany;

#[MorphToMany(Tag::class, 'taggable')]
class Post extends Model
{
}

// ...

Post::first()->tags;
```

```
use Illuminate\Database\Eloquent\Model;
use Vajexal\AttributeRelations\Relations\MorphedByMany;

#[MorphedByMany(Post::class, 'taggable')]
class Tag extends Model
{
}

// ...

Tag::first()->posts;
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1813d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/72415539?v=4)[vajexal](/maintainers/vajexal)[@vajexal](https://github.com/vajexal)

---

Top Contributors

[![vajexal](https://avatars.githubusercontent.com/u/72415539?v=4)](https://github.com/vajexal "vajexal (11 commits)")

---

Tags

laraveleloquentRelationshipsattribute

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vajexal-laravel-attributes-relationships/health.svg)

```
[![Health](https://phpackages.com/badges/vajexal-laravel-attributes-relationships/health.svg)](https://phpackages.com/packages/vajexal-laravel-attributes-relationships)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[betterapp/laravel-db-encrypter

Provides database model attribute encryption/decryption

365614.7k8](/packages/betterapp-laravel-db-encrypter)[indexzer0/eloquent-filtering

Powerful eloquent filtering

22425.9k3](/packages/indexzer0-eloquent-filtering)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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