LaravelPackages.net
Acme Inc.
Toggle sidebar
soysaltan/appender

Take your appends control in Laravel 5.6+

24
2
1.0.0
About soysaltan/appender

soysaltan/appender is a Laravel package for take your appends control in laravel 5.6+. It currently has 2 GitHub stars and 24 downloads on Packagist (latest version 1.0.0). Install it with composer require soysaltan/appender. Discover more Laravel packages by soysaltan or browse all Laravel packages to compare alternatives.

Last updated

Laravel Appender

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads


While working with Laravel, sometimes you have to return fields that are not in your db table (https://laravel.com/docs/8.x/eloquent-serialization#appending-values-to-json). However, you may want to hide these fields that you add in some cases. In this case, you need to dominate the eloquent model.Now, you can do it easily with this package.

This package includes a Appends trait. You can use the Appends trait in any model you want. For example, if you want to add to the User model:

class User extends Model
{
    use HasFactory, Appends; // <--add this; 
    ...

Installation

You can install the package via composer for Laravel 5.6+:

composer require soysaltan/appender

Usage

class User extends Model
{
    use HasFactory, Appends; // <--add this; 
    
    protected $appends = ['created_at_by_human', 'created_at_formatted'];

If you want to get your model without appends, just drop this line

User::$withoutAppends=true; // User -> your user mmodel

Note: If your model extends a custom class, you need to ensure that your extended class has Concerns\HasAttributes trait.Otherwise this package doesn't work since it uses Concerns\HasAttributes::getArrayableAppends method


Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments