I want to print a button in my Laravel (blade) views. I have made a function for creating this button, because of: if the user, who loads the view, doesn't have rights to see this button, the button won't show up (I haven't made this part yet). In every view where I need a button for something, I want to use this method. The return value of the method is:
<a href="{{ URL::to(scholen/toevoegen) }}"><button class="btn btn-primary">Nieuwe school</button></a>
There is just a problem: the method createButton() returns a string. So, {{ URL::to('scholen/toevoegen') }} doesn't work in blade.
Is there a solution for this? I don't want to type the url in my method, becuase of it has to be variable.
View
<?= Authorize::createButton('Nieuwe school', array('scholen', 'toevoegen'), null, 'btn btn-primary'); ?>
Helper Class
static function createButton($text = null, $route = null, $id = null, $class = null)
{
$button = '<a href="{{ URL::to(<!URL!>) }}"><button class="<!CLASS!>"><!TEXT!></button></a>';
if ($text != null) {
$button = str_replace("<!TEXT!>", $text, $button);
}
if ($route[0] != null && $route[1] != null) {
$button = str_replace("<!URL!>", $route[0] .'/'. $route[1] . ($id != null ? '/'. $id : ''), $button);
}
if ($class != null) {
$button = str_replace("<!CLASS!>", $class, $button);
}
return $button;
}