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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners