<p>MY SOLUTION</p>

<p>Use <code>setAttributes</code> and set the second argument <code>$safeOnly</code> to false</p>

<pre><code>$fieldsService = Craft::$app-&gt;getFields();
$field = $fieldsService-&gt;getFieldByHandle('productImages');
// Update 'limit' value to be empty in order to accept as many images as needed
$field-&gt;setAttributes([
    'limit' =&gt; ''
],false);
$fieldsService-&gt;saveField($field);
</code></pre>

CC BY-SA 4.0
2018-10-20T23:42:06.913Z
2018-10-20T23:42:06.913Z
Hector
<p>I need to update the limit setting for Images allowed to be empty, so as to allow for no limit. How do I go about updating the 'limit' setting?</p>

<pre><code>$fieldsService = Craft::$app-&gt;getFields();
$field = $fieldsService-&gt;getFieldByHandle('productImages');
// Need to update 'limit' to equal '' (currently limited to '5')
// Then save the new setting
$fieldsService-&gt;saveField($field);
</code></pre>

<p><strong><em>SOLUTION</em></strong></p>

<p>I was able to accomplish this by using <code>setAttributes</code> and setting the second argument <code>$safeOnly</code> to <code>false</code></p>

<pre><code>$field-&gt;setAttributes([
    'limit' =&gt; ''
],false);
</code></pre>

CC BY-SA 4.0
2018-10-19T04:48:36.767Z
`$field->limit = '' ` does the trick as well
Robin Schambach
CC BY-SA 4.0
2018-10-20T02:54:05.713Z
@Hector can you add what worked for you as an official answer?
Brad Bell
<plugin-development><field><image><limit>
Update field setting value using getFieldByHandle
# Update field setting value using getFieldByHandle

(Asked by: username_0 on 2018-10-18)

I need to update the limit setting for Images allowed to be empty, so as to allow for no limit. How do I go about updating the 'limit' setting?
$fieldsService = Craft::$app->getFields();
$field = $fieldsService->getFieldByHandle('productImages');
// Need to update 'limit' to equal '' (currently limited to '5')
// Then save the new setting
$fieldsService->saveField($field);

SOLUTION
I was able to accomplish this by using setAttributes and setting the second argument $safeOnly to false
$field->setAttributes([
    'limit' => ''
],false);

**Tags:** plugin-development, field, image, limit
> **Comments:**
> **username_1**: `$field->limit = '' ` does the trick as well  
> **username_2**: @Hector can you add what worked for you as an official answer?  

---

## 1 answers

### Answer by username_0 on 2018-10-20. Score: 2 | Accepted answer

MY SOLUTION
Use setAttributes and set the second argument $safeOnly to false
$fieldsService = Craft::$app->getFields();
$field = $fieldsService->getFieldByHandle('productImages');
// Update 'limit' value to be empty in order to accept as many images as needed
$field->setAttributes([
    'limit' => ''
],false);
$fieldsService->saveField($field);


---

