Closed eugenem closed 5 years ago
Even if I configure it at subcat, cat, and order by cat, if will look like cat / cat all the time
@eugenem can you give source of Section, Models? and try it by (5.6.4 tag)
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;
}
}
@eugenem Π° ΠΏΠΎΡΠ΅ΠΌΡ ΡΡ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΡ ΠΌΠΎΠ΄Π΅Π»Π΅ΠΉ ΡΠ΅ΡΠ΅Π· ΡΠ΅ΡΠ²ΠΈΡ ΠΏΡΠΎΠ²Π°ΠΉΠ΄Π΅Ρ?https://sleepingowladmin.ru/docs/model_configuration_section
Π’Π°ΠΊ ΠΈΡΡΠΎΡΠΈΡΠ΅ΡΠΊΠΈ ΡΠ»ΠΎΠΆΠΈΠ»ΠΎΡΡ. Π ΠΊΠ°ΠΊΠ°Ρ ΡΠ°Π·Π½ΠΈΡΠ°?
ΠΠΎΠΆΠ΅Ρ ΠΈ Π½ΠΈ ΠΊΠ°ΠΊΠΎΠΉ. ΠΠΎ ΡΠ²ΠΎΠ΅ΠΉ Π·Π°Π΄Π°ΡΠ΅, ΡΠ΅ΡΠΈΠ»ΠΎΡΡ ΠΈΠ»ΠΈ ΡΠ°ΠΊ ΠΎΡΡΠ°Π»ΠΎΡΡ Π²ΡΠ΅?
ΠΡΠΎΠ²Π΅ΡΠΈΠ», ΠΎΡΠΈΠ±ΠΊΠΈ Π½Π΅Ρ
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:
subcat 1 | cat subcat 2 | cat
But in this case, table is broken:
cat | cat cat | cat