Skip to content

paramientos/appender

Repository files navigation

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.

About

Laravel Appender, manage your appends easily

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages