I'm developing a Wordpress plugin that requires strict data for the frontend. The frontend is built with Vue.js and it's basically a multistep wizard where every step is represented by a specific Vue component.

This is how I enforced validation rules for my step's data array: final class YoutubeVideo extends Step {

/** * Step data validator * * @var Factory */ private $validation; /** * Step data validation rules * * @var array */ private $validation_rules = []; ... and then we need instantiate our validator in the constructor: $loader = new FileLoader( new Filesystem(), 'lang' ); $translator = new Translator( $loader, 'en' ); $this->validation = new Factory( $translator, new Container()); I'm not gonna add any localization files for the error messages because I won't display them.

In the array casting function of course: /** * Get step as array * * @return mixed */ public function to_array() { $this->validate_data(); return get_object_vars( $this ); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners