@@ -148,6 +148,31 @@ $post = $this->shared('post');
148148$allShared = $this->shared();
149149```
150150
151+ ### Attribute casting
152+
153+ The $casts property on your shortcode class provides a convenient method of converting attributes to
154+ common data types. The $casts property should be an array where the key is the name of the attribute
155+ being cast and the value is the type you wish to cast the column to. The supported cast types are:
156+ ` int ` , ` integer ` , ` real ` , ` float ` , ` double ` , ` boolean ` , ` array ` (comma separated values) and ` date ` .
157+
158+ ``` blade
159+ class YourShortcode extends Shortcode
160+ {
161+ /**
162+ * The attributes that should be cast to native types.
163+ *
164+ * @var array
165+ */
166+ protected $casts = [
167+ 'show_ids' => 'array',
168+ ];
169+ }
170+ ```
171+
172+ Now the ` show_ids ` attribute will always be cast to an array when you access it.
173+ (array attributes are casted from comma separated string, eg. "1,2,3").
174+
175+
151176### Option to not throw exceptions from views
152177
153178There is a useful option to aviod server (500) error for whole page when one of shortocode views has thrown an exception.
@@ -159,19 +184,6 @@ This will render exception details in the place of a shortcode and will not cras
159184It will still log exception to a log file and report to [ Sentry] ( https://sentry.io/ ) if it's integrated.
160185
161186
162- ### Comma separated values (array attributes)
163-
164- If you need to pass an array to a shortcode, you can pass values separated by comma:
165-
166- ``` blade
167- [posts_list ids="1,2,3"]
168- ```
169-
170- Then in the ` render ` function you can parse this attribute using built-in method:
171- ``` php
172- $ids = $this->parseCommaSeparated($atts['ids']);
173- ```
174-
175187### Generate data for documentation
176188
177189There can be hundreds of registered shortcodes and having a way to show documentation for all
@@ -199,11 +211,9 @@ $ vendor/bin/phpunit
199211
200212## TODO
201213
202- 1 . Casting attributes (int, bool, array (comma separated))
203- 1 . Add basic bootstrap shortcodes set
2042141 . Attributes validation
205- 1 . Add Debugbar integration tests
2062151 . Add custom widget for debugbar integration
216+ 1 . Add Debugbar integration tests
2072171 . Create performance profile tests, optimize performance
208218
209219## Contributing
0 commit comments