PHP code example of beyondcode / laravel-tag-helper
1. Go to this page and download the library: Download beyondcode/laravel-tag-helper 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/ */
beyondcode / laravel-tag-helper example snippets
namespace BeyondCode\TagHelper\Helpers;
use BeyondCode\TagHelper\Helper;
use BeyondCode\TagHelper\Html\HtmlElement;
class CustomTagHelper extends Helper
{
protected $targetAttribute = 'custom';
protected $targetElement = 'div';
public function process(HtmlElement $element)
{
// Manipulate the DOM element
}
}
namespace BeyondCode\TagHelper\Helpers;
use BeyondCode\TagHelper\Helper;
use BeyondCode\TagHelper\Html\HtmlElement;
class CustomLink extends Helper
{
protected $targetElement = 'my-custom-link';
public function process(HtmlElement $element)
{
$element->setTag('a');
}
}
namespace BeyondCode\TagHelper\Helpers;
use BeyondCode\TagHelper\Helper;
use BeyondCode\TagHelper\Html\HtmlElement;
class CustomLink extends Helper
{
protected $targetAttribute = 'route';
protected $targetElement = 'a';
public function process(HtmlElement $element)
{
$element->setAttribute('href', route($element->getAttribute('route')));
$element->removeAttribute('route');
$element->setAttribute('title', 'This is a link.');
}
}
namespace BeyondCode\TagHelper\Helpers;
use BeyondCode\TagHelper\Helper;
use BeyondCode\TagHelper\Html\HtmlElement;
class CustomLink extends Helper
{
protected $targetAttribute = 'add-hidden-field';
protected $targetElement = 'form';
public function process(HtmlElement $element)
{
$element->removeAttribute('add-hidden-field');
$element->appendInnerText('<input type="hidden" name="hidden" />');
// $element->prependInnerText('');
// $element->setInnerText('');
}
}
namespace BeyondCode\TagHelper\Helpers;
use BeyondCode\TagHelper\Helper;
use BeyondCode\TagHelper\Html\HtmlElement;
class CustomForm extends Helper
{
protected $targetElement = 'form';
public function process(HtmlElement $element)
{
$formMethod = $element->getAttribute('method');
}
}
namespace BeyondCode\TagHelper\Helpers;
use BeyondCode\TagHelper\Helper;
use BeyondCode\TagHelper\Html\HtmlElement;
class CustomForm extends Helper
{
protected $targetElement = 'a';
protected $targetAttribute = 'route';
public function process(HtmlElement $element)
{
$element->setAttribute('href', "{{ route(" . $element->getAttributeForBlade('route') . ") }}");
$element->removeAttribute('route');
}
}
// this works
<form
csrf action="/posts"
class="mt-8>
// this doesn't work
<form
csrf
action="/posts"
class="mt-8>
html
<form csrf method="post">
</form>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.