FrozenNode / Laravel-Administrator

An administrative interface package for Laravel
http://administrator.frozennode.com/
MIT License
1.94k stars 504 forks source link

How to change column value depending on selection of other field using relationship field #1054

Closed anarbayramov closed 7 years ago

anarbayramov commented 7 years ago

Hi, I let user to choose participation values from panel. Depending on selection I have to change columns is_participant to 1

this is my field on AdminPanel

'participant' => [
            'title' => 'administrator.fields_watcher',
            'type' => 'relationship',
            'name_field' => 'name',
            'options_sort_field' => 'name',    
],

This is my model file

 public function challenges()
    {
        return $this->belongsToMany(Challenge::class, 'role_challenge', 'role_id', 'challenge_id');
    }

 public function participant()
    {
        return $this->challenges()->where('is_participant','=',TRUE)
        ->where('is_watcher','=',TRUE);
    }

enter image description here

And this is my database table

enter image description here

So basically when user choose a challenge (test1, test2, test3) to participant field I want to change is_participant value to 1 in database if it is not exist will add new line with is_participant value is 1.

I can add new line when I choose (test1, test2,test3) but I cannot change column values.

thank you