{"_id":"57b80485f442340e00b0170f","category":{"_id":"57b80485f442340e00b01706","__v":0,"version":"57b80485f442340e00b01701","project":"56363c690441020d0000e9da","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-01T16:28:25.131Z","from_sync":false,"order":4,"slug":"fields","title":"Fields"},"__v":0,"user":"55d48e9283130a250029b3cd","parentDoc":null,"project":"56363c690441020d0000e9da","version":{"_id":"57b80485f442340e00b01701","project":"56363c690441020d0000e9da","__v":1,"createdAt":"2016-08-20T07:19:33.761Z","releaseDate":"2016-08-20T07:19:33.761Z","categories":["57b80485f442340e00b01702","57b80485f442340e00b01703","57b80485f442340e00b01704","57b80485f442340e00b01705","57b80485f442340e00b01706","57b80485f442340e00b01707","57b80485f442340e00b01708","57b80485f442340e00b01709","57b80485f442340e00b0170a","57b80485f442340e00b0170b"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0-dev","version":"1.0.0-dev"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-01T17:38:35.415Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Fields are a core part of an admin panel, that's why they are first-class citizens in Artificer.\n\nIn your **fields.php** config file yo can find:\n\n- classmap\n- types\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Class Map\"\n}\n[/block]\nThis is the point were you can add custom fields. Refer to [Adding a field](/docs/adding-a-field) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Types\"\n}\n[/block]\nBy default, Artificer tries to match the field type name with the column name. \n\nHowever, in most cases, you will need something more complex than that. In this example we could match one of those column names:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n...\\n  \\n'checkbox' => [\\n\\n\\t'autodetect' => [\\n      'accept',\\n      'active',\\n      'boolean',\\n      'activated',\\n      'confirmed',\\n\\t\\t\\t'you get the idea',\\n  ],\\n\\n],\",\n      \"language\": \"php\",\n      \"name\": \"Autodetect\"\n    }\n  ]\n}\n[/block]\nSometimes you don't want to specify a name but you follow some convention. You can add regex when this happens:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n...\\n\\n'datetime' => [\\n\\n // For example: 'created_at' \\n  'regex' => [\\n    '/_at$/',\\n    '/_on$/',\\n  ],\\n\\t\\n  ...\\n\\n],\",\n      \"language\": \"php\",\n      \"name\": \"Regex\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Type detection in detail\",\n  \"body\": \"Once one of the following checks is truthy that type is the selected one.\\n\\n1. Match in *regex*\\n2. Type match (equal)\\n3. Match in *autodetect*\\n4. Type name similar\\n5. Default type\"\n}\n[/block]\nAlso you may want a type to have specific attributes:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n...\\n  \\n'text' => [\\n\\n  \\\"attributes\\\" => [\\n  \\t'class' => 'form-control',\\n  ],\\n  \\n],\",\n      \"language\": \"php\",\n      \"name\": \"Attributes\"\n    }\n  ]\n}\n[/block]\nIf you need to add behaviour to a field you can do it by using Field Widgets:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n...\\n\\n'date' => [\\n  'autodetect' => [\\n  \\t'_at'\\n  ],\\n\\n  'widgets' => [\\n  \\t\\\\Mascame\\\\Artificer\\\\Widgets\\\\DateTimepicker::class,\\n  ]\\n],\",\n      \"language\": \"php\",\n      \"name\": \"Widgets\"\n    }\n  ]\n}\n[/block]\nIf there was no type match, it will fallback to the default value:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n...\\n  \\n'default' => [\\n\\t'type' => 'text'\\n]\",\n      \"language\": \"php\",\n      \"name\": \"Default type\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"introduction-to-fields","type":"basic","title":"Introduction"}
Fields are a core part of an admin panel, that's why they are first-class citizens in Artificer. In your **fields.php** config file yo can find: - classmap - types [block:api-header] { "type": "basic", "title": "Class Map" } [/block] This is the point were you can add custom fields. Refer to [Adding a field](/docs/adding-a-field) [block:api-header] { "type": "basic", "title": "Types" } [/block] By default, Artificer tries to match the field type name with the column name. However, in most cases, you will need something more complex than that. In this example we could match one of those column names: [block:code] { "codes": [ { "code": "<?php\n\n...\n \n'checkbox' => [\n\n\t'autodetect' => [\n 'accept',\n 'active',\n 'boolean',\n 'activated',\n 'confirmed',\n\t\t\t'you get the idea',\n ],\n\n],", "language": "php", "name": "Autodetect" } ] } [/block] Sometimes you don't want to specify a name but you follow some convention. You can add regex when this happens: [block:code] { "codes": [ { "code": "<?php\n\n...\n\n'datetime' => [\n\n // For example: 'created_at' \n 'regex' => [\n '/_at$/',\n '/_on$/',\n ],\n\t\n ...\n\n],", "language": "php", "name": "Regex" } ] } [/block] [block:callout] { "type": "info", "title": "Type detection in detail", "body": "Once one of the following checks is truthy that type is the selected one.\n\n1. Match in *regex*\n2. Type match (equal)\n3. Match in *autodetect*\n4. Type name similar\n5. Default type" } [/block] Also you may want a type to have specific attributes: [block:code] { "codes": [ { "code": "<?php\n\n...\n \n'text' => [\n\n \"attributes\" => [\n \t'class' => 'form-control',\n ],\n \n],", "language": "php", "name": "Attributes" } ] } [/block] If you need to add behaviour to a field you can do it by using Field Widgets: [block:code] { "codes": [ { "code": "<?php\n\n...\n\n'date' => [\n 'autodetect' => [\n \t'_at'\n ],\n\n 'widgets' => [\n \t\\Mascame\\Artificer\\Widgets\\DateTimepicker::class,\n ]\n],", "language": "php", "name": "Widgets" } ] } [/block] If there was no type match, it will fallback to the default value: [block:code] { "codes": [ { "code": "<?php\n\n...\n \n'default' => [\n\t'type' => 'text'\n]", "language": "php", "name": "Default type" } ] } [/block]