Created
March 8, 2018 15:04
-
-
Save MrAtiebatie/eccea0c4a48147a9737fb94e0d5584ae to your computer and use it in GitHub Desktop.
Custom Blade directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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