[英]laravel share variable in all views as reference
我真的想要一個很簡單的東西
1)我從 AppServiceProvider 共享一個全局變量,如下所示
public function boot() {
view()->share('css', new CSS());
}
2)我在視圖(index.blade.php)中設置了一些屬性值,例如blow
$css->publicProperty = "Something"; // changed in index.blade.php
3)在另一個視圖(contact.blade.php)中,我檢查了$css->publicProperty變量,但它沒有給我更改值
dd($css->publicProperty) // give me the initial value in contact.blade.php
現在我需要一種共享變量作為全局變量也作為參考的方法。
這樣我在一個視圖中更改,它也會保留其他視圖中的更改。
您應該在控制器上使用 session。
像這樣設置會話:
Session::put('name','css');
您可以像這樣更改視圖:
{{Session::put('name','css')}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.