AttachAction problem with Relations?
When I try to "Attach" a Panel(resource) in Group(resource), I get this error.
Group-Model:
Panel-Model:
GroupResource:
PanelsRelationManager:
SQL-Scheme:
So now; why is it looking for groups instead of group?
Group-Model:
namespace App\Models;
use ...
class Group extends Model
{
use HasFactory;
protected ...
public function panels(): HasMany
{
return $this->hasMany(Panel::class, 'group_id', 'id');
}
}namespace App\Models;
use ...
class Group extends Model
{
use HasFactory;
protected ...
public function panels(): HasMany
{
return $this->hasMany(Panel::class, 'group_id', 'id');
}
}Panel-Model:
namespace App\Models;
use ...
class Panel extends Model
{
use HasFactory;
protected ...
public function group(): BelongsTo
{
return $this->belongsTo(Group::class, 'group_id', 'id');
}
}namespace App\Models;
use ...
class Panel extends Model
{
use HasFactory;
protected ...
public function group(): BelongsTo
{
return $this->belongsTo(Group::class, 'group_id', 'id');
}
}GroupResource:
public static function getRelations(): array
{
return [
RelationManagers\PanelsRelationManager::class,
//
];
} public static function getRelations(): array
{
return [
RelationManagers\PanelsRelationManager::class,
//
];
}PanelsRelationManager:
class PanelsRelationManager extends RelationManager
{
protected static string $relationship = 'panels';
public function form(Form $form): Form
{
return PanelResource::form($form);
}
public function table(Table $table): Table
{
return $table
...
->headerActions([
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['title', 'table_name', 'module_name', 'metadata'])
->preloadRecordSelect()
->recordSelectOptionsQuery(fn (Builder $query) => $query->where('lang', $this->getOwnerRecord()->lang))
])
->...
}
}class PanelsRelationManager extends RelationManager
{
protected static string $relationship = 'panels';
public function form(Form $form): Form
{
return PanelResource::form($form);
}
public function table(Table $table): Table
{
return $table
...
->headerActions([
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['title', 'table_name', 'module_name', 'metadata'])
->preloadRecordSelect()
->recordSelectOptionsQuery(fn (Builder $query) => $query->where('lang', $this->getOwnerRecord()->lang))
])
->...
}
}SQL-Scheme:
-- ----------------------------
-- Table structure for group
-- ----------------------------
DROP TABLE IF EXISTS `group`;
CREATE TABLE `group` (
`id` int NOT NULL AUTO_INCREMENT,
`-- ...
PRIMARY KEY (`id`) USING BTREE
);
-- ----------------------------
-- Table structure for panel
-- ----------------------------
DROP TABLE IF EXISTS `panel`;
CREATE TABLE `panel` (
`id` int NOT NULL AUTO_INCREMENT,
`group_id` int DEFAULT NULL, -- group(group_id)
-- ...
PRIMARY KEY (`id`) USING BTREE,
);-- ----------------------------
-- Table structure for group
-- ----------------------------
DROP TABLE IF EXISTS `group`;
CREATE TABLE `group` (
`id` int NOT NULL AUTO_INCREMENT,
`-- ...
PRIMARY KEY (`id`) USING BTREE
);
-- ----------------------------
-- Table structure for panel
-- ----------------------------
DROP TABLE IF EXISTS `panel`;
CREATE TABLE `panel` (
`id` int NOT NULL AUTO_INCREMENT,
`group_id` int DEFAULT NULL, -- group(group_id)
-- ...
PRIMARY KEY (`id`) USING BTREE,
);So now; why is it looking for groups instead of group?
