Call to undefined method Illuminate\View\Compilers\BladeCompiler::components()
lexdubyna opened this issue · comments
lexdubyna commented
Hello,
As I amtrying to use Illuminate\View
separately from Laravel, I am now using the solution from app/bootloader.php
, and on a separate page without any additional logic it works great. Here's the code:
<?php
require_once 'vendor/autoload.php';
use Clickfwd\Yoyo\Blade\Application;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Jenssegers\Blade\Blade;
$app = Application::getInstance();
$app->bind(ApplicationContract::class, Application::class);
$app->alias('view', ViewFactory::class);
$blade = new Blade([__DIR__ . '/views'], __DIR__ . '/compiled', $app);
$blade->compiler()->components([
'components.alert' => 'alert'
]);
$templateData = [
'title' => 'Title',
'text' => 'This is my text!'
];
echo $blade->render('page', $templateData);
But when I try putting it in a separate class I am getting Fatal error: Uncaught Error: Call to undefined method Illuminate\View\Compilers\BladeCompiler::components()
:
...
use Clickfwd\Yoyo\Blade\Application;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Jenssegers\Blade\Blade as JenssegersBlade;
class Blade
{
private JenssegersBlade $blade;
public function __construct()
{
$app = Application::getInstance();
$app->bind(ApplicationContract::class, Application::class);
$app->alias('view', ViewFactory::class);
$this->blade = new JenssegersBlade(
[get_template_directory() . '/views'],
get_template_directory() . '/compiled',
$app
);
// Custom anonymous components
$this->blade->compiler()->components([
'components.media-image' => 'media-image'
]);
}
}
When I comment out $this->blade->compiler()->components
part - everything works fine (except for the anonymous component).
Please help.
lexdubyna commented
Sorry, didn't notice additional dependencies conflict.