Check if variable exist in laravel's blade directive
问题 I'm trying to create blade directive which echo variable (if variable defined) or echo "no data" if variable undefined. This is my code in AppServiceProvider.php : <?php namespace App\Providers; use Blade; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Blade::directive('p', function($ex) { error_log(print_r($ex,true)); return '<?php $defined_vars = get_defined