p-andrey/tentacles
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
mindtwo/laravel-auto-create-uuid
Automatically generate UUIDs for Eloquent models on creation and replication.
29,604
1
jenssegers/model
An Laravel eloquent-like model class, for Laravel and other frameworks
4,726,510
395
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 3.0 | >=5.5.0 | ^5.5| | MIT | |
| 2.1 | >=5.5.0 | ^5.5| | MIT | |
| 2.0 | >=5.5.0 | ^5.5| | MIT | |
| 1.3 | >=5.5.0 | ^5.5| | MIT | |
| 1.2 | >=5.5.0 | ^5.5| | MIT | |
| 1.1 | >=5.5.0 | ^5.5| | MIT | |
| 1.0 | >=5.5.0 | 5.* | MIT |