benjivm/returnable

This package is abandoned and no longer maintained. No replacement package was suggested.

Eloquent model column select trait.

0.1.9 2020-09-16 17:18 UTC

This package is auto-updated.

Last update: 2023-03-16 22:52:53 UTC


README

This Laravel trait limits the columns an Eloquent model can return. As opposed to $visible and $hidden this trait will only select the specified columns.

Installation

Use composer: composer require benjivm/returnable

Usage

Add the trait to your model:

namespace App\Models;

use Benjivm\Returnable\ReturnableTrait;
use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    use ReturnableTrait;

    protected $returnable = ['Name', 'ConNum', 'Address', 'City', 'State', 'Zip', 'PhoneNum', 'EMailAddress', 'Country', 'Url'];

Only the specified columns will be returned when the Model is loaded unless you have manually specified the columns in the instantiation, e.g. Customer::select('MyColumn as aliased_column').