PHPackages                             rvkolosov/laravel-withtrait - 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. rvkolosov/laravel-withtrait

ActiveLibrary

rvkolosov/laravel-withtrait
===========================

WithTrait for dynamic load relations in Laravel Model.

14PHP

Since Jun 21Pushed 6y agoCompare

[ Source](https://github.com/rvkolosov/laravel-withtrait)[ Packagist](https://packagist.org/packages/rvkolosov/laravel-withtrait)[ RSS](/packages/rvkolosov-laravel-withtrait/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel 5 WithTrait
-------------------

[](#laravel-5-withtrait)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e7d56d033e1c60be20aff41384be2c086a6c7d75714a4d5817ba43af308757bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72766b6f6c6f736f762f6c61726176656c2d7769746874726169742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rvkolosov/laravel-withtrait)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/2cec51af9603a5025b2f8905bb5d410e56c7d436f22f219fef4a6973baa3631f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f72766b6f6c6f736f762f6c61726176656c2d7769746874726169742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/rvkolosov/laravel-withtrait)[![Total Downloads](https://camo.githubusercontent.com/694378a13db7d5f9eeaeef3216a353e8e2612f8b2b9b3fc50cd4a5d10df14d02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72766b6f6c6f736f762f6c61726176656c2d7769746874726169742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rvkolosov/laravel-withtrait)

Requirements
------------

[](#requirements)

The package has been tested in the following configuration:

- PHP version &gt;= 7.1.3
- Laravel Framework version &gt;= 5.8

### Install

[](#install)

Require this package with composer using the following command:

```
composer require rvkolosov/laravel-withtrait
```

### Configuration

[](#configuration)

Enable trait in your model:

```
use RVKolosov\LaravelWithTrait\WithTrait;
use App\Models\Image;

class Post extends Model
{
    use WithTrait;

    public function images()
    {
        return $this->hasMany(Image::class);
    }
}
```

For index method of controller use `withRelations()`:

```
use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        return Post::withRelations()->get();
    }
}
```

For show method of controller use `loadRelations()`:

```
use App\Models\Post;

class PostController extends Controller
{
    public function show(Post $post)
    {
        return $post->loadRelations();
    }
}
```

### Usage

[](#usage)

You can dynamically load relations in `GET` request.

Load relations for list:

`GET http://example.com/post?with[]=images`

Load relations for one object:

`GET http://example.com/posts/1?with[]=images`

### License

[](#license)

The Laravel WithTrait is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f66b02881cb580a68e281f9fd97dc84faf68c52f1a6b1bd52f33ccab840c84d?d=identicon)[rvkolosov](/maintainers/rvkolosov)

---

Top Contributors

[![rvkolosov](https://avatars.githubusercontent.com/u/46761969?v=4)](https://github.com/rvkolosov "rvkolosov (10 commits)")[![ivan770](https://avatars.githubusercontent.com/u/14003886?v=4)](https://github.com/ivan770 "ivan770 (6 commits)")

### Embed Badge

![Health badge](/badges/rvkolosov-laravel-withtrait/health.svg)

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

PHPackages © 2026

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