veloxia / markup
Schema markup for Laravel.
v1.0
2020-01-18 12:23 UTC
Requires
- php: ^7.1
- illuminate/support: ^6.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-11-18 23:43:58 UTC
README
Some Schema.org generators made to be used with Laravel.
Installation
Install via Composer
composer require veloxia/markup
Laravel < 5.4
Add to config/app.php
'providers' => [ ... Veloxia\Markup\MarkupServiceProvider::class, ... ]; 'aliases' => [ ... 'Markup' => Veloxia\Markup\Facades\Markup::class, ... ];
Newer versions of Laravel
The Service Provider should be available automatically when the installation is complete. Otherwise try the procedure above.
Usage
// https://schema.org/FAQPage // either ... $markup = \Veloxia\Markup\Markup::make('FAQ'); // ... or ... $markup = Markup::make('FAQ'); // ... then add some data ... $markup ->question("Sunt in culpa qui officia deserunt?") ->answer("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."); $markup ->question("Casus mixtus cum culpa?") ->answer("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); // ... and print the results echo $markup->json(); // with blade you'll need to allow html // {!! $markup->json() !!}
This will output something like:
<script type="application/ld+json"> { "@context": "https:\/\/schema.org", "@type": "FAQPage", "mainEntity": [ { "@type": "Question", "name": "Sunt in culpa qui officia deserunt?", "acceptedAnswer": { "@type": "Answer", "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." } }, { "@type": "Question", "name": "Casus mixtus cum culpa?", "acceptedAnswer": { "@type": "Answer", "text": "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." } } ] } </script>
It's also possible to bulk-insert:
// Just one Q/A pair at a time ... $markup->question("Question here", "Answer here")->json(); // ... or a bigger array $faq = (new \Veloxia\Markup\Generators\FAQ([ "Question 1" => "Answer A", "Question 2" => "Answer B", ]))->json();
Testing
composer test
Contributing
Feel free to make changes :)
Credits
License
The MIT License (MIT). Please see License File for more information.