66use Illuminate \Contracts \Support \Arrayable ;
77use Illuminate \Support \Arr ;
88use Illuminate \Support \Str ;
9- use stdClass ;
10- use Yajra \DataTables \Exceptions \Exception ;
119
1210class Helper
1311{
@@ -58,12 +56,12 @@ protected static function isItemOrderInvalid($item, $array)
5856 *
5957 * @param mixed $content Pre-processed content
6058 * @param array $data data to use with blade template
61- * @param mixed $param parameter to call with callable
59+ * @param array|object $param parameter to call with callable
6260 * @return mixed
6361 *
6462 * @throws \Exception
6563 */
66- public static function compileContent ($ content , array $ data , $ param )
64+ public static function compileContent ($ content , array $ data , array | object $ param )
6765 {
6866 if (is_string ($ content )) {
6967 return static ::compileBlade ($ content , static ::getMixedValue ($ data , $ param ));
@@ -102,10 +100,10 @@ public static function compileBlade($str, $data = [])
102100 * Get a mixed value of custom data and the parameters.
103101 *
104102 * @param array $data
105- * @param mixed $param
103+ * @param array|object $param
106104 * @return array
107105 */
108- public static function getMixedValue (array $ data , $ param )
106+ public static function getMixedValue (array $ data , array | object $ param )
109107 {
110108 $ casted = self ::castToArray ($ param );
111109
@@ -123,26 +121,16 @@ public static function getMixedValue(array $data, $param)
123121 /**
124122 * Cast the parameter into an array.
125123 *
126- * @param mixed $param
124+ * @param array|object $param
127125 * @return array
128- *
129- * @throws \Yajra\DataTables\Exceptions\Exception
130126 */
131- public static function castToArray ($ param ): array
127+ public static function castToArray (array | object $ param ): array
132128 {
133- if (is_array ($ param )) {
134- return $ param ;
135- }
136-
137- if ($ param instanceof stdClass) {
138- return (array ) $ param ;
139- }
140-
141129 if ($ param instanceof Arrayable) {
142130 return $ param ->toArray ();
143131 }
144132
145- throw new Exception ( ' Invalid parameter type. ' ) ;
133+ return ( array ) $ param ;
146134 }
147135
148136 /**
@@ -169,8 +157,10 @@ public static function getOrMethod($method)
169157 */
170158 public static function convertToArray ($ row , $ filters = [])
171159 {
172- $ row = is_object ($ row ) && method_exists ($ row , 'makeHidden ' ) ? $ row ->makeHidden (Arr::get ($ filters , 'hidden ' , [])) : $ row ;
173- $ row = is_object ($ row ) && method_exists ($ row , 'makeVisible ' ) ? $ row ->makeVisible (Arr::get ($ filters , 'visible ' , [])) : $ row ;
160+ $ row = is_object ($ row ) && method_exists ($ row , 'makeHidden ' ) ? $ row ->makeHidden (Arr::get ($ filters , 'hidden ' ,
161+ [])) : $ row ;
162+ $ row = is_object ($ row ) && method_exists ($ row , 'makeVisible ' ) ? $ row ->makeVisible (Arr::get ($ filters , 'visible ' ,
163+ [])) : $ row ;
174164 $ data = $ row instanceof Arrayable ? $ row ->toArray () : (array ) $ row ;
175165
176166 foreach ($ data as &$ value ) {
0 commit comments