Loop through all created fields and get the field type I want to show some input fields on frontend template form.


  Type of input is dependent on the type of fields selected on the backend.


For example, if the text field is selected in the backend I will create a field of type="text". If a number field is selected I will show an input type="number" in the template.

I am trying to get the field type in my plugin.

$fields = Craft::$app-&gt;fields-&gt;getAllFields();
        foreach ($fields as $field) {
             $output[(int) $field-&gt;id] = array(
                'id'            =&gt; (int) $field-&gt;id,
                'handle'        =&gt; $field-&gt;handle,
                'name'          =&gt; $field-&gt;name,
                'instructions'  =&gt; $field-&gt;instructions
            );
        }


I checked the /vendor/craftcms/cms/src/services/Fields.php but not found any method.

Update:
I checked a few files and i found a method which returns the string.

$field-&gt;displayName();



Number
Lightswitch


Is it the only way to get the type of field.
Making sure you include use craft\db\Query; at the top of your Class, you can do something like this:

$fields = (new Query())
    -&gt;select(['id','handle','name','instructions','type'])
    -&gt;from(['{{%fields}}'])
    -&gt;all();

foreach ($fields as $field) {
    $output[(int) $field['id']] = array(
        'id'            =&gt; (int) $field['id'],
        'handle'        =&gt; $field['handle'],
        'name'          =&gt; $field['name'],
        'instructions'  =&gt; $field['instructions'],
        'type'          =&gt; $field['type']
    );
}