php - how to exclude certain views with laravel view composer -
how can make sure load data via view composer select views , exclude few, 2 views specific? can use regex instead of '*'?
public function boot() { view()->composer( '*', 'app\http\viewcomposers\profilecomposer' ); }
there 2 views i'd avoid, extend same blade used others, not sure declaring 99 others best - if can define ones left out that'd great.
perhaps not best way doing can done this
in services provider register view composer
public function boot() { view()->composer( '*', 'app\http\viewcomposers\profilecomposer' ); }
in profilecomposer
compose method view class repository type hinted. use name of current name of view , make condition excluded view name.
class profilecomposer { public function __construct() { // dependencies automatically resolved service container... } /** * bind data view. * * @param view $view * @return void */ public function compose(view $view) { $excludedviews = ['firstview','secondview']; //check if current view not in excludedviews array if(!in_array($view->getnmae() , $excludedviews)) { $view->with('dataname', $this->data); } } }
Comments
Post a Comment