Skip to content

Instantly share code, notes, and snippets.

@MrAtiebatie
Created March 8, 2018 15:04
Show Gist options
  • Save MrAtiebatie/eccea0c4a48147a9737fb94e0d5584ae to your computer and use it in GitHub Desktop.
Save MrAtiebatie/eccea0c4a48147a9737fb94e0d5584ae to your computer and use it in GitHub Desktop.
Custom Blade directive
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
Blade::directive('edit', function ($arguments) {
$args = explode(', ', str_replace("'", '', $arguments));
$result = "<a href='" . route($args[0], $args[1]) . "'>Edit</a>";
return '<?php echo "' . $result . '"; ?>';
});
}
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment