| Package Data | |
|---|---|
| Maintainer Username: | greabock |
| Maintainer Contact: | greabock@gmail.com (Greabock) |
| Package Create Date: | 2015-02-16 |
| Package Last Update: | 2021-02-03 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-23 03:03:40 |
| Package Statistics | |
|---|---|
| Total Downloads: | 34,298 |
| Monthly Downloads: | 21 |
| Daily Downloads: | 1 |
| Total Stars: | 37 |
| Total Watchers: | 4 |
| Total Forks: | 15 |
| Total Open Issues: | 0 |
Monkey-patching for eloquent models
Composer
"greabock/tentacles": "dev-master"
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;