<p>You have to loop the Matrix field first, something like this:</p>

<pre><code>foreach($entry-&gt;matrixHandle-&gt;all() as $block) {
   echo $block-&gt;fieldHandle;
}
</code></pre>

CC BY-SA 4.0
2020-02-04T12:41:34.060Z
thanks @gioppe  i should have used one() or all() because it returns craft\elements\db\MatrixBlockQuery and i had to get result first
user9975
CC BY-SA 4.0
2020-02-04T08:20:51.483Z
2020-02-04T08:20:51.483Z
gioppe
<p>I am trying to process a text field inside a Matrix field.</p>

<p>In the controller I have this to get posted params:</p>

<pre><code>$element-&gt;setFieldValuesFromRequest($fieldsLocation);
</code></pre>

<p>If I want to process a custom text field, I can do it easily with</p>

<pre><code>$result=$element-&gt;getFieldValue('textFieldHandle')
</code></pre>

<p>which <code>$result</code> is exactly the text field value.</p>

<p>but if I have this text field in Matrix field, if I do this:</p>

<pre><code>$result=$element-&gt;getFieldValue('matrixFieldHandle')
craft::dd($result)
</code></pre>

<p>I get a <code>craft\elements\db\MatrixBlockQuery</code> object which I don't know how I can fetch text value from this object. </p>

<craft3><matrix>
How to process Matrix field in controller
# How to process Matrix field in controller

(Asked by: username_0 on 2020-02-03)

I am trying to process a text field inside a Matrix field.
In the controller I have this to get posted params:
$element->setFieldValuesFromRequest($fieldsLocation);

If I want to process a custom text field, I can do it easily with
$result=$element->getFieldValue('textFieldHandle')

which $result is exactly the text field value.
but if I have this text field in Matrix field, if I do this:
$result=$element->getFieldValue('matrixFieldHandle')
craft::dd($result)

I get a craft\elements\db\MatrixBlockQuery object which I don't know how I can fetch text value from this object.

**Tags:** craft3, matrix


---

## 1 answers

### Answer by username_1 on 2020-02-04. Score: 2 | Accepted answer

You have to loop the Matrix field first, something like this:
foreach($entry->matrixHandle->all() as $block) {
   echo $block->fieldHandle;
}

> **Comments:**
> **username_0**: thanks @username_1  i should have used one() or all() because it returns craft\elements\db\MatrixBlockQuery and i had to get result first  

---

