22
33namespace MarcoRieser \Livewire \Tags ;
44
5- use Illuminate \Support \Collection ;
65use Livewire \Features \SupportScriptsAndAssets \SupportScriptsAndAssets ;
76use Livewire \Mechanisms \FrontendAssets \FrontendAssets ;
87use Statamic \Support \Arr ;
@@ -62,7 +61,7 @@ public function component(): string
6261 /**
6362 * This will return the value of a computed property.
6463 *
65- * {{ livewire:computed property="my-component" }}
64+ * {{ livewire:computed:my_computed_property }}
6665 */
6766 public function computed ()
6867 {
@@ -71,42 +70,20 @@ public function computed()
7170 }
7271
7372 $ property = Str::replace ([': ' , '. ' ], ': ' , $ property );
74-
75- if (! Str::contains ($ property , ': ' )) {
76- return \Livewire \Livewire::current ()?->$ property ;
77- }
78-
7973 $ path = collect (explode (': ' , $ property ));
8074 $ property = $ path ->shift ();
8175
82- return $ path
83- ->reduce (function ($ carry , string $ property ) {
84- if ($ carry === null ) {
85- return $ carry ;
86- }
87-
88- if (is_array ($ carry )) {
89- return Arr::get ($ carry , $ property );
90- }
76+ $ property = collect ([$ property , Str::camel ($ property ), Str::snake ($ property )])
77+ ->filter (fn (string $ property ) => method_exists (\Livewire \Livewire::current (), $ property ))
78+ ->first ();
9179
92- if ($ carry instanceof Collection) {
93- return $ carry ->get ($ property );
94- }
95-
96- if (is_object ($ carry )) {
97- $ property = Str::before ($ property , '( ' );
98-
99- if (method_exists ($ carry , $ property )) {
100- return $ carry ->{$ property }();
101- }
80+ if (! $ property ) {
81+ return null ;
82+ }
10283
103- if (property_exists ($ carry , $ property )) {
104- return $ carry ->{$ property };
105- }
106- }
84+ // TODO[mr]: support public properties or methods on objects in nested data (12.04.2025 mr)
10785
108- return null ;
109- }, \Livewire \Livewire::current ()->$ property );
86+ return Arr::get (\Livewire \Livewire::current ()->$ property , $ path ->join (': ' ));
11087 }
11188
11289 /**
0 commit comments