This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm working on modification of users because I want a morphed profile for many different types of data from the same list of users. I can get the profiles attached and to make things easy, I'm using separate forms for each type of user to fill out. The class setup sounds good and works on extracting and displaying the data, but I'm unable to see how to get the October form to display and connect to related relation fields. (e.g. in this case trying to use the fileupload widget on the form to adjust the avatar for the user on a related profile)
User.php update
public $morphTo = ['profile'];
Consumer.php code
public $morphOne = [ 'user' => ['Newuser\Models\User', 'type' => 'profile', 'name' => 'consumer'] ];
consumer fields.yaml
===================================
# Field Definitions
# ===================================
fields:
first_name:
span: left
label: newuser::lang.user.fields.first_name
last_name:
span: right
label: newuser::lang.user.fields.last_name
title:
span: left
label: newuser::lang.user.fields.title
middle_i:
span: right
label: newuser::lang.user.fields.middle_i
login:
span: left
label: newuser::lang.user.fields.login
password:
type: password
span: left
label: newuser::lang.user.fields.password
permissions: backend.change_password
password_confirmation:
type: password
span: right
label: newuser::lang.user.fields.password_confirmation
permissions: backend.change_password
address1:
span: left
label: newuser::lang.user.fields.address1
address2:
span: right
label: newuser::lang.user.fields.address2
city:
span: left
label: newuser::lang.user.fields.city
state:
span: right
label: newuser::lang.user.fields.state
zip:
span: left
label: newuser::lang.user.fields.zip
class:
type: dropdown
label: newuser::lang.user.fields.class
permissions: backend.edit_class
context: [create, update]
locations:
label: newuser::lang.user.fields.location_ids
type: checkboxcolumns
columns: 4
viewRows: 10
context: [create, update]
phone:
span: left
label: newuser::lang.user.fields.phone
email:
span: right
label: newuser::lang.user.fields.email
enews:
label: newuser::lang.user.fields.enews
type: checkbox
bio:
label: newuser::lang.user.fields.bio
type: richeditor
size: huge
commentAbove: newuser::lang.user.comments.bio
send_invite:
context: create
type: checkbox
label: newuser::lang.user.fields.send_invite
commentAbove: newuser::lang.user.comments.send_invite
tabs:
fields:
permissions[superuser]:
context: [create, update]
tab: newuser::lang.user.tabs.permissions
label: newuser::lang.user.fields.superuser
type: checkbox
comment: newuser::lang.user.comments.superuser
permissions: superuser
groups:
context: [create, update]
tab: newuser::lang.user.tabs.permissions
label: newuser::lang.user.fields.groups
commentAbove: newuser::lang.user.comments.groups
type: checkboxlist
secondaryTabs:
fields:
avatar:
label: newuser::lang.user.fields.avatar
type: s3fileupload
mode: image
imageHeight: 260
imageWidth: 260
obviously title, bio, enews etc. are fields defined in the consumer profile table.
When I run the consumer controller and view the create path to get the form, I get an error:
Call to undefined method October\Rain\Database\QueryBuilder::avatar()
I don't get why It's not reading the user model for the avatar, and I'm not knowledgeable enough about October yet to know how this connection should be made.
Last updated
I have exhausted my abilities to deal with this. The only thing I can see that might work would be to write a new partial per profile and call it from javascript on a drop down change for the user profile type. I've tried to use the relation controller, i've tried to just allow Eloquent to handle the data exchange, and I've tried rewriting part of the file upload widget thinking there might be something I could do in there. I'm leaving this here and open because I would really like to have someone's input on on this, and maybe have a solution for future issues and projects.
For now I am collecting all profile data from all types into the new user class and controlling what is shown with permissions. (I have previously rewritten the form controller to my own version that allows field specific permissions.)
If anyone has any thoughts on how to have October handle data applied to a relation when dealing with that relation's relations and not end up in the position I found myself, I would be grateful.
For this one. One thing i do to handle this is to generate custom field by adding relation fields in fields.yaml:
table_name[field_name]:
to save the field in database i call beforeSave() in model get the param by using post("TableName[fieldName]") since that is the name of the input on the form. I know this is not the clean way. I've been searching the documentations and really hoping for better solutions.
Last updated
1-3 of 3