Maknz\Slack\Attachment::setFields PHP Method

setFields() public method

Set the fields for the attachment.
public setFields ( array $fields )
$fields array
    public function setFields(array $fields)
    {
        $this->clearFields();
        foreach ($fields as $field) {
            $this->addField($field);
        }
        return $this;
    }

Usage Example

 public function testSetFields()
 {
     $a = new Attachment(['fallback' => 'Fallback', 'text' => 'Text']);
     $a->addField(['title' => 'Title 1', 'value' => 'Value 1', 'short' => true])->addField(['title' => 'Title 2', 'value' => 'Value 2', 'short' => true]);
     $this->assertSame(2, count($a->getFields()));
     $a->setFields([]);
     $this->assertSame(0, count($a->getFields()));
 }