Open misog opened 6 years ago
What's your file name?
On Mar 17, 2018, at 5:49 PM, misog notifications@github.com wrote:
@form_text('name') is just processed as string "@form_text('name')" in view file
I think the problem is with $this->app->afterResolving() in HtmlServiceProvider.php:
/** * Register Blade directives. * * @return void */ protected function registerBladeDirectives() { // <--- here it runs ---> $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { // <--- here it does not run ---> $namespaces = [ 'Html' => get_class_methods(HtmlBuilder::class), 'Form' => get_class_methods(FormBuilder::class), ]; foreach ($namespaces as $namespace => $methods) { foreach ($methods as $method) { if (in_array($method, $this->directives)) { $snakeMethod = Str::snake($method); $directive = strtolower($namespace).'_'.$snakeMethod; $bladeCompiler->directive($directive, function ($expression) use ($namespace, $method) { return "<?php echo $namespace::$method($expression); ?>"; }); } } } }); }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
File name of my view file? create.blade.php As a workaround I copied the anonymous function with some changes from above and inserted it into App\Providers\AppServiceProvider.php and now form blade directives work:
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$namespaces = [
'Html' => get_class_methods(\Collective\Html\HtmlBuilder::class),
'Form' => get_class_methods(\Collective\Html\FormBuilder::class),
];
foreach ($namespaces as $namespace => $methods) {
foreach ($methods as $method) {
if (in_array($method, $this->form_directives)) {
$snakeMethod = \Illuminate\Support\Str::snake($method);
$directive = strtolower($namespace).'_'.$snakeMethod;
Blade::directive($directive, function ($expression) use ($namespace, $method) {
return "<?php echo $namespace::$method($expression); ?>";
});
}
}
}
}
Hmm, I haven't heard of this problem. Does it not work with a fresh install of both laravel and the package?
On Mar 17, 2018, at 6:35 PM, misog notifications@github.com wrote:
Filename of my view file? create.blade.php
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
Indeed, directives do not work on fresh L5.6 with just LaravelCollective/html installed. Steps to reproduce with PHP 7.2 on Windows:
Collective\Html\HtmlServiceProvider::class,
to config/app.php
'Form' => Collective\Html\FormFacade::class,
and 'Html' => Collective\Html\HtmlFacade::class,
to config/app.php
{!! Form::text('first') !!} // works
@form_text('second') // does not work, shown as text
@form_text('second')
why the @ in front of it?
@form_text('name')
is just not processed and is placed as text "@form_text('name')" in view filesI think the problem is with $this->app->afterResolving() in HtmlServiceProvider.php: