1. Go to this page and download the library: Download area17/twill-transformers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
area17 / twill-transformers example snippets
namespace App\Transformers;
use A17\TwillTransformers\Transformer as TwillTransformer;
abstract class Transformer extends TwillTransformer
{
/**
* @return array|null
*/
public function transform()
{
return $this->sanitize([
'template_name' => $this->makeTemplateName(),
'header' => $this->transformHeader($this->data),
$this->makePageKey() => $this->transformData($this->data),
'seo' => $this->transformSeo($this->data),
'footer' => $this->transformFooter($this->data),
]);
}
}
public static function blade($transformer, $data): array
{
if (app()->bound(BladeTransformer::class)) {
return app(BladeTransformer::class)->transform($transformer, $data);
}
return [];
}
namespace App\Transformers;
class Posts extends Transformer
{
public function transform(): array
{
return [
'title' => $this->title,
];
}
public function transformStorybookData(): array
{
return [
'title' => 'Fake Title to Be Displayed Inside Storybook Only',
];
}
}