This case must be considered as two separate conditions. It is not possible to check if the value is present only in the "new values" array, because during the record 'created' event, "role_id" will not appear in the "old values" array yet, so we will get ErrorException "Trying to get property 'role_id' of non-object ". I think that it would also be worth considering one place where we could define what values from the array in each instance should be converted into what values provided by us. :)
This case must be considered as two separate conditions. It is not possible to check if the value is present only in the "new values" array, because during the record 'created' event, "role_id" will not appear in the "old values" array yet, so we will get ErrorException "Trying to get property 'role_id' of non-object ". I think that it would also be worth considering one place where we could define what values from the array in each instance should be converted into what values provided by us. :)