1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Laravel Voyager Admin Panel Can Not See Accessor

Discussão em 'Outras Linguagens' iniciado por sundowatch, Outubro 1, 2024 às 11:04.

  1. sundowatch

    sundowatch Guest

    I have Product and Category model. Category entities takes parent_id which is linked to Category itself. I want to see full category tree on the admin panel. I'm trying to define an accessor named as "full_path" to the Category model. So I will use this in the Product model with category field. Here is code:

    <?php

    namespace App;
    use Illuminate\Database\Eloquent\Model;
    use TCG\Voyager\Traits\Translatable;

    class Category extends Model
    {
    use Translatable;
    protected $translatable = ['name', 'description'];
    public $additional_attributes = ['full_path'];

    public function withTranslation() {
    return $this->load('translations');
    }

    public function getFullPathReadAttribute()
    {
    $path = $this->name;
    $parent = $this->parent;

    while ($parent) {
    $path = $parent->name . ' > ' . $path;
    $parent = $parent->parent;
    }

    return $path;
    }
    }


    But I can not see the full_path attribute when I'm creating a bread for Product.category: [​IMG]

    What am I missing?

    Continue reading...

Compartilhe esta Página