public function boot()
{
$this->app['events']->listen('locale.changed', function ($locale) {
$this->app['xe.translator']->setLocale($locale);
});
$this->app['validator']->extend('LangRequired', function ($attribute, $value) {
$fields = $this->app['request']->all();
$protocol = 'xe_lang_preprocessor://';
$prefix = null;
foreach ($fields as $key => $val) {
if (starts_with($key, $protocol)) {
if ($val == $attribute) {
$prefix = substr($key, 0, strrpos($key, '/'));
break;
}
}
}
$locale = $this->app['xe.translator']->getLocale();
$name = $prefix . '/locale/' . $locale;
$validator = null;
foreach ($fields as $key => $val) {
if ($name == $key) {
$validator = $this->app['validator']->make([$attribute => $val], [$attribute => 'Required']);
}
}
if ($validator === null) {
return false;
}
return $validator->passes();
}, 'The :attribute field is required.');
}