File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
src/Services/Data/Computors Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 33namespace LaravelEnso \Tables \Services \Data \Computors ;
44
55use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Support \Collection ;
7+ use Illuminate \Support \Str ;
68use LaravelEnso \Helpers \Services \Obj ;
79use LaravelEnso \Tables \Contracts \ComputesModelColumns ;
810
@@ -21,9 +23,17 @@ public static function columns($columns): void
2123 public static function handle (Model $ row )
2224 {
2325 foreach (self ::$ columns as $ column ) {
24- $ row ->{$ column ->get ('name ' )} = $ row ->{$ column ->get ('name ' )}();
26+ $ method = self ::segments ($ column ->get ('name ' ))->last ();
27+ $ row ->{$ column ->get ('name ' )} = self ::segments ($ column ->get ('name ' ))
28+ ->slice (0 , -1 )->reduce (fn ($ value , $ segment ) => $ value ->{$ segment }, $ row )
29+ ->{$ method }();
2530 }
2631
2732 return $ row ;
2833 }
34+
35+ private static function segments (string $ attribute ): Collection
36+ {
37+ return Str::of ($ attribute )->explode ('. ' );
38+ }
2939}
You can’t perform that action at this time.
0 commit comments