This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi, i'm trying to extend the rainlab.User plugin.
here's my boot function of my plugin :
public function boot() {
UsersController::extendFormFields(function($form, $model, $context){
$form -> addTabFields([
'game' => [
'label' => 'Jeu choisi',
'type' => 'relation',
'tab' => 'Profile'
]
]);
});
}
my problem is the following : game has to be a relation to another plugin table (raskrial.gamelist, table is : raskrial_gamelist_games). games can belong to many users, but users can only have one selected at the time. how i should do that ?
thx all.
You need to extend the related models and add the relations using the $belongsToMany[] and $hasOne[] arrays. see here:
https://octobercms.com/docs/database/relations#relationship-types
i'm able to extend the user with my plugin. the current error i'm getting is this one :
Model 'RainLab\User\Models\User' does not contain a definition for 'lseusers[game]'.
in my plugin file, i'm adding fields in tab like this :
$form->addTabFields([
'lseusers[gamertag]' => [
'label' => 'gamertag',
'tab' => 'LSE infos',
'type' => 'text'
],
'lseusers[game]' => [
'label' => 'game',
'tab' => 'LSE infos',
'type' => 'relation',
'nameFrom' => 'game_selection'
],
as for my model config file :
public $hasOne = [
'game_selection' => 'Raskrial\GameManager\Models\Game'
];
i'm not sure what i'm doing wrong here ... thx for the help
in the boot function, i define a relation to the UserModel as such :
UserModel::extend(function($model){
$model -> hasOne['lseusers'] = ['Raskrial\LseUsers\Models\LseUsers'];
});
then i extend the form fields as seen in the last post. when i declared
'nameFrom' => 'game_selection'
i also made a relation in my lseusers model as such :
public $hasOne = [
'game_selection' => 'Raskrial\GameManager\Models\Game'
];
what i trying to accomplish:
- i have a plugin called raskrial.lseusers which extend the rainlab.user plugin
- in the new fields extended by raskrial.lseusers, i need to have a relation with another plugin : raskrial.gamemanager for a list of game that the user can select on creation or edition.
1-8 of 8