Skip to content

#11 add support for selectable attributes

Choose a tag to compare

@gregorip02 gregorip02 released this 21 Jun 22:57
· 62 commits to stable since this release

This minor version adds a function in the trait that allows the developer to determine what attributes their clients can obtain from their models.

<?php

namespace App;

// ...
use Restql\Traits\RestqlAttributes;

class Book extends Model
{
    use RestqlAttributes;

     /**
     * Get the fillable attributes for selects.
     *
     * @return array
     */
    public function onSelectFillables(): array
    {
        if ($this->isPrivate) {
            return ['title', 'created_at'];
        }

        return $this->getFillable();
    }
}