LaravelRUS / SleepingOwlAdmin

πŸ¦‰ Administrative interface builder for Laravel (Laravel admin)
http://sleepingowladmin.ru/
MIT License
805 stars 217 forks source link

seems to be a bug at AdminColumn:text #899

Closed eugenem closed 5 years ago

eugenem commented 6 years ago

version: latest 4.*@dev

These are columns for Subcategory model. It has 'name' field, same as Category model. Subcategory belongs to Category.

In this case table looks fine:

                AdminColumn::text('name')->setLabel('Name'),
                AdminColumn::text('category.name')->setLabel('Category'),

subcat 1 | cat subcat 2 | cat

But in this case, table is broken:

                AdminColumn::text('category.name')->setLabel('Category'),
                AdminColumn::text('name')->setLabel('Name'),

cat | cat cat | cat

eugenem commented 6 years ago

Even if I configure it at subcat, cat, and order by cat, if will look like cat / cat all the time

ghost commented 6 years ago

@eugenem can you give source of Section, Models? and try it by (5.6.4 tag)

eugenem commented 6 years ago

same

AdminSection::registerModel(\App\Models\Subcategory::class, function (ModelConfiguration $model) {
    #$model->setTitle('משΧͺΧžΧ©Χ™Χ');
    // Display
    $model->onDisplay(function () {
        return AdminDisplay::datatables()
            ->setHtmlAttribute('class', 'table-primary')
            ->setColumns([
                AdminColumn::text('name','Name'),
                AdminColumn::text('category.name','Category'),
                AdminColumn::text('description','Description'),

            ])->paginate(25);
    });
    // Create And Edit
    $model->onCreateAndEdit(function() {
        return AdminForm::panel()->addBody([
            AdminFormElement::select('category_id', 'Category', new App\Models\Category())->setDisplay('name'),
            AdminFormElement::text('name', 'Name'),
            AdminFormElement::text('description', 'Description'),
        ]);
    });
});

class Category extends \Eloquent
{
    public $timestamps = false;

    protected $guarded = ['id'];

    #use \SleepingOwl\Admin\Traits\OrderableModel;

    public function getOrderField()
    {
        return 'ordr';
    }

    public function subcategories()
    {
        return $this->hasMany('App\Models\Subcategory');
    }

    public function products()
    {
        return $this->hasMany('App\Models\Product');
    }

    public static function getList()
    {
        $vals = [];
        foreach( self::all() as $item )
            $vals[$item->id] = $item->name;

        return $vals;
    }

}

class Subcategory extends \Eloquent
{
    public $timestamps = false;

    protected $guarded = ['id'];

    #use \SleepingOwl\Admin\Traits\OrderableModel;

    public function getOrderField()
    {
        return 'ordr';
    }

    public function scopeDefaultSort( $query )
    {
        return $query->orderBy( 'ordr', 'asc' );
    }

    public function category()
    {
        return $this->belongsTo('App\Models\Category');
    }

    public function products()
    {
        return $this->hasMany('App\Models\Product');
    }

    public function getTitleAttribute()
    {
        return "{$this->category->name} - {$this->name}";
    }

    public static function getList()
    {
        $vals = [];
        foreach( Subcategory::orderBy( 'category_id', 'asc' )->with( 'category' )->get() as $item )
            $vals[$item->id] = "{$item->category->name} - {$item->name}";

        return $vals;
    }
}
Butochnikov commented 5 years ago

@eugenem Π° ΠΏΠΎΡ‡Π΅ΠΌΡƒ Ρ‚Ρ‹ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΡˆΡŒ ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡŽ ΠΌΠΎΠ΄Π΅Π»Π΅ΠΉ Ρ‡Π΅Ρ€Π΅Π· сСрвис ΠΏΡ€ΠΎΠ²Π°ΠΉΠ΄Π΅Ρ€?https://sleepingowladmin.ru/docs/model_configuration_section

eugenem commented 5 years ago

Π’Π°ΠΊ историчСски слоТилось. А какая Ρ€Π°Π·Π½ΠΈΡ†Π°?

Butochnikov commented 5 years ago

ΠœΠΎΠΆΠ΅Ρ‚ ΠΈ Π½ΠΈ ΠΊΠ°ΠΊΠΎΠΉ. По Ρ‚Π²ΠΎΠ΅ΠΉ Π·Π°Π΄Π°Ρ‡Π΅, Ρ€Π΅ΡˆΠΈΠ»ΠΎΡΡŒ ΠΈΠ»ΠΈ Ρ‚Π°ΠΊ ΠΎΡΡ‚Π°Π»ΠΎΡΡŒ всС?

daaner commented 5 years ago

ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΈΠ», ошибки Π½Π΅Ρ‚