p-andrey/tentacles

Da epic tentacles for Eloquent
13,806 1
Install
composer require p-andrey/tentacles
Latest Version:3.0
PHP:>=5.5.0
Laravel:5 – 10
License:MIT
Last Updated:Apr 7, 2023
Links: GitHub  ·  Packagist
Maintainer: p-andrey

tentacles

Monkey-patching for eloquent models

Composer

"p-andrey/tentacles": "^3.0"

user-model...

<? namespace App\User\Models;

use Illuminate\Database\Eloquent\Model;
use Greabock\Tentacles\EloquentTentacle;

User extends Model {
  
  use EloquentTentacle;

}

ServiceProvider

<?php namespace App\Article\Providers;

use Illuminate\Support\ServiceProvider;
use App\Article\Models\Article;
use App\User\Models\User;


use Illuminate\Database\Eloquent\Model;

class ArticleProvider extends ServiceProvider {

  public function register()
  {
    #..
  }
  
  public function boot()
  {
    User::addExternalMethod('articles', function()
    {
        return $this->hasMany(Article::class);
    });


    User::addExternalMethod('getFullnameAttribute', function()
    {
        return $this->first_name . ' ' . $this->last_name; 
    });
  }
  
}

Now we can do this:

$user = User::with('articles')->first();

$fullname = $user->fullname;

Related Packages

greabock/tentacles

Da epic tentacles for Eloquent

34,545 36
mindtwo/laravel-auto-create-uuid

Automatically generate UUIDs for Eloquent models on creation and replication.

29,604 1
wwardaww/laravel-id-cryption

A trait for Laravel/Lumen Model id encryption.

37 0
jenssegers/model

An Laravel eloquent-like model class, for Laravel and other frameworks

4,726,510 395
czim/laravel-nestedupdater

Eloquent model updater for nested relations data for Laravel.

54,026 19

Version History

Version Released PHP Laravel License
3.0 >=5.5.0 ^5.5|^6|^7|^8.0|^9.0|^10.0 MIT
2.1 >=5.5.0 ^5.5|^6|^7|^8.0|^9.0 MIT
2.0 >=5.5.0 ^5.5|^6|^7|^8.0 MIT
1.3 >=5.5.0 ^5.5|^6|^7|^8.0 MIT
1.2 >=5.5.0 ^5.5|^6|^7 MIT