You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
This is probably just a misunderstanding of my part but there's something strange related to the FormAccessible trait when dealing with relations.
First of all, is this trait supposed to be dealing with relations ? Or is the developer expected to write form mutators for relations ? If so, just ignore this :)
So I've got this model that defines a relation :
class Content {
use FormAccessible;
public function content_type()
{
return $this->belongsTo(ContentType::class);
}
}
if I call $content->getFormValue('content_type') it returns null, because :
1 - there is no form mutator for content_type in this model
2 -The FormAccessible trait sees 'content_type' as a nested key and forward the call like so : return \data_get($relatedModel, empty($key) ? null : $key); with, in this case, $relatedModel being a ContentType object and $key being still 'content_type'.
Obviously there is no 'content_type' attribute on the ContentType object.
Moreover, if I call $content->getFormValue('content_type.id') it's searching for a form mutator in ContentType called formContentType.idAttribute on the ContentType object, which isn't a valid php method name.
Wouldn't it make more sense to return the ContentType object when there is no form mutator in that object, or even better the key of the relation if the key isn't a nested key ?
So it would do :
$content->getFormValue('content_type'); //returns the primary key of the ContentType object
$content->getFormValue('content_type.name'); //returns a string or the result of the method formNameAttribute of the ContentType object
What do you think ?
The text was updated successfully, but these errors were encountered:
ryssbowh
changed the title
triat FormAccessible bug ?
trait FormAccessible bug ?
Apr 12, 2020
ryssbowh
changed the title
trait FormAccessible bug ?
trait FormAccessible bug ? (version 5.4.0)
Apr 12, 2020
Hi there,
This is probably just a misunderstanding of my part but there's something strange related to the FormAccessible trait when dealing with relations.
First of all, is this trait supposed to be dealing with relations ? Or is the developer expected to write form mutators for relations ? If so, just ignore this :)
So I've got this model that defines a relation :
if I call
$content->getFormValue('content_type')
it returns null, because :1 - there is no form mutator for content_type in this model
2 -The FormAccessible trait sees 'content_type' as a nested key and forward the call like so :
return \data_get($relatedModel, empty($key) ? null : $key);
with, in this case, $relatedModel being a ContentType object and $key being still 'content_type'.Obviously there is no 'content_type' attribute on the ContentType object.
Moreover, if I call
$content->getFormValue('content_type.id')
it's searching for a form mutator in ContentType calledformContentType.idAttribute
on the ContentType object, which isn't a valid php method name.Wouldn't it make more sense to return the ContentType object when there is no form mutator in that object, or even better the key of the relation if the key isn't a nested key ?
So it would do :
What do you think ?
The text was updated successfully, but these errors were encountered: