@@ -155,7 +155,7 @@ common data types. The $casts property should be an array where the key is the n
155155being cast and the value is the type you wish to cast the column to. The supported cast types are:
156156` int ` , ` integer ` , ` real ` , ` float ` , ` double ` , ` boolean ` , ` array ` (comma separated values) and ` date ` .
157157
158- ``` blade
158+ ``` php
159159class YourShortcode extends Shortcode
160160{
161161 /**
@@ -173,12 +173,37 @@ Now the `show_ids` attribute will always be cast to an array when you access it.
173173(array attributes are casted from comma separated string, eg. "1,2,3").
174174
175175
176- ### Option to not throw exceptions from views
176+ ### Attribute validation
177+
178+ There is a simple way to validate attributes.
179+ Error messages will be rendered on the shortcode place.
180+ For convenients it will return attributes.
181+
182+ ``` php
183+ class YourShortcode extends Shortcode
184+ {
185+ /**
186+ * Render shortcode
187+ *
188+ * @param string $content
189+ * @return string
190+ */
191+ public function render($content)
192+ {
193+ $atts = $this->validate([
194+ 'post_id' => 'required|numeric|exists:posts,id',
195+ ]);
196+
197+ //
198+ }
199+ }
200+ ```
201+
202+ ### Option to not throw exceptions from shortcodes
177203
178- There is a useful option to aviod server (500) error for whole page when one of shortocode views has thrown an exception.
204+ There is a useful option to aviod server (500) error for whole page when one of shortocode has thrown an exception.
179205
180206To enable it set ` 'throw_exceptions' => false, ` in the ` shortcodes.php ` config file.
181- It works only when ` $this->view('some-view'); ` method is used in the shortcode class.
182207
183208This will render exception details in the place of a shortcode and will not crash whole page request with 500 error.
184209It will still log exception to a log file and report to [ Sentry] ( https://sentry.io/ ) if it's integrated.
@@ -211,8 +236,6 @@ $ vendor/bin/phpunit
211236
212237## TODO
213238
214- 1 . Integrate Laravel Telescope
215- 1 . Attributes validation
2162391 . Add custom widget for debugbar integration
2172401 . Create performance profile tests, optimize performance
218241
0 commit comments