Transporters are just not needed and don't add any meaningful value because:
Removal of "Transporters" and use Request object instead.
None. Suggestions are welcome.
Take this example:
Let's say we reached the point where we need to pass data from Action -> Task and we have 30 fields in either Transporter or Request which doesn't matter and our Task needs all those 30 fields.
What can we do here? We can do one of this:
$transporter->toArray() or $request->all() (best solution IMO)As you can see here, Transporters actually don't solve anything at all, because all Request data are just present in Transporters as well and they are basically the same data wise. And all fields that are in Request usually end up in Transporters (allowed) properties.
Here look at a more Transporterish example:
Note: We just can't set additionalProperties => false right now as explained here.
This is just an example of Transporter bugs which are many.
But for this examples sake let's say we can set additionalProperties => false
'properties' => [
'first_field',
'second_field',
'third_field',
],
// allow for undefined properties
'additionalProperties' => false,
to get this exact functionality we just can use:
$data = $data->sanitizeInput([
'first_field',
'second_field',
'third_field',
]);
and to get the functionality of 'additionalProperties' => true, well you get it already with Request object $request->all() and even if you want to sanitize known fields + have unknow fields (additionalProperties) we can do something about that by implementing something like this $request->sanitizeInputAndKeepAdditionalProperties() (I'm not good at naming :|)
This is possible to remove transporters layer and add its advantages (Like default values) to Request concept!
This is a good decision for sake of simplicity and avoiding code duplication, because we all know naming all input fields in 2 places (transporter and request) is not a good practice!
I've never used transporter in my project.
I always add AdditionalProperties in request with $this->offsetSet('someKey', $someValue);.
eg.
/**
* @return array
*/
public function rules()
{
return [
'id' => [
'required',
function ($attribute, $value, $fail)
{
$innerAllotOrder = InnerAllotOrder::query()
->where([
['id', $value],
])
->first();
if (!$innerAllotOrder) {
return $fail($this->attributes()[$attribute].'不存在');
}
if ($innerAllotOrder->status != InnerAllotOrder::STATUS_SUBMIT) {
return $fail($this->attributes()[$attribute].'已调拨,不支持更新');
}
$this->offsetSet('innerAllotOrder', $innerAllotOrder);
}
],
'remark' => 'string',
];
}
Since Transporters finally have been removed in version 10.0 I close this issue.
Most helpful comment
This is possible to remove transporters layer and add its advantages (Like
default values) toRequestconcept!This is a good decision for sake of simplicity and avoiding code duplication, because we all know naming all input fields in 2 places (
transporterandrequest) is not a good practice!