This commit is contained in:
Marcel Pociot
2020-04-29 22:05:03 +02:00
parent 6cf206e0a2
commit b515a55325
27 changed files with 215 additions and 253 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Concerns;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use function GuzzleHttp\Psr7\stream_for;
trait LoadsViews
{
protected function getView(string $view, array $data = [])
{
$templatePath = implode(DIRECTORY_SEPARATOR, explode('.', $view));
$twig = new Environment(
new ArrayLoader([
'app' => file_get_contents(base_path('resources/views/server/layouts/app.twig')),
'template' => file_get_contents(base_path('resources/views/'.$templatePath.'.twig')),
])
);
return stream_for($twig->render('template', $data));
}
}