1212use Encore \Admin \Grid \Model ;
1313use Encore \Admin \Grid \Row ;
1414use Encore \Admin \Grid \Tools ;
15+ use Encore \Admin \Traits \ShouldSnakeAttributes ;
1516use Illuminate \Database \Eloquent \Model as Eloquent ;
1617use Illuminate \Database \Eloquent \Relations ;
1718use Illuminate \Support \Collection ;
@@ -33,6 +34,7 @@ class Grid
3334 Concerns \HasSelector,
3435 Concerns \CanHidesColumns,
3536 Concerns \CanFixColumns,
37+ ShouldSnakeAttributes,
3638 Macroable {
3739 __call as macroCall;
3840 }
@@ -385,7 +387,7 @@ protected function addRelationColumn($name, $label = '')
385387 return $ this ;
386388 }
387389
388- $ name = Str::snake ($ relation ).'. ' .$ column ;
390+ $ name = ( $ this -> shouldSnakeAttributes () ? Str::snake ($ relation ) : $ relation ) .'. ' .$ column ;
389391
390392 $ this ->model ()->with ($ relation );
391393
@@ -842,7 +844,9 @@ protected function handleRelationColumn($method, $label)
842844 ) {
843845 $ this ->model ()->with ($ method );
844846
845- return $ this ->addColumn ($ method , $ label )->setRelation (Str::snake ($ method ));
847+ return $ this ->addColumn ($ method , $ label )->setRelation (
848+ $ this ->shouldSnakeAttributes () ? Str::snake ($ method ) : $ method
849+ );
846850 }
847851
848852 if ($ relation instanceof Relations \HasMany
@@ -852,7 +856,7 @@ protected function handleRelationColumn($method, $label)
852856 ) {
853857 $ this ->model ()->with ($ method );
854858
855- return $ this ->addColumn (Str::snake ($ method ), $ label );
859+ return $ this ->addColumn ($ this -> shouldSnakeAttributes () ? Str::snake ($ method ) : $ method , $ label );
856860 }
857861
858862 return false ;
0 commit comments