registerHtmlBuilder(); $this->registerFormBuilder(); $this->app->alias('html', 'Collective\Html\HtmlBuilder'); $this->app->alias('form', 'Collective\Html\FormBuilder'); $this->setBladeDirectives('Html', get_class_methods(HtmlBuilder::class)); $this->setBladeDirectives('Form', get_class_methods(FormBuilder::class)); } /** * Register the HTML builder instance. * * @return void */ protected function registerHtmlBuilder() { $this->app->singleton('html', function ($app) { return new HtmlBuilder($app['url'], $app['view']); }); } /** * Register the form builder instance. * * @return void */ protected function registerFormBuilder() { $this->app->singleton('form', function ($app) { $form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->getToken()); return $form->setSessionStore($app['session.store']); }); } /** * Set blade directives * * @param string $type * @param array $methods * * @return void */ protected function setBladeDirectives($namespace, $methods) { foreach ($methods as $method) { if (in_array($method, $this->directives)) { $snakeMethod = Str::snake($method); $directive = strtolower($namespace).'_'.$snakeMethod; Blade::directive($directive, function($expression) use ($namespace, $method) { return ""; }); } } } /** * Get the services provided by the provider. * * @return array */ public function provides() { return ['html', 'form', 'Collective\Html\HtmlBuilder', 'Collective\Html\FormBuilder']; } }