kundefine
5 months ago

laravel share variable in all views as reference

Posted 5 months ago by kundefine

I really want a very simple thing

  1. I Share a global variable from AppServiceProvider like below
public function boot() {
    view()->share('css', new CSS());
}
  1. I set some property values it In a View (index.blade.php) like blow
$css->publicProperty = "Something"; // changed in index.blade.php
  1. In another View (contact.blade.php) i check the $css->publicProperty variable but it doesn't give me the change value
dd($css->publicProperty) // give me the initial value in contact.blade.php

Now i need a way that share a variable as global also as reference. So that i change in one view and it will retain the change in other views also

Please sign in or create an account to participate in this conversation.