Skip to content

Commit 648191b

Browse files
committed
1 parent ad7fc75 commit 648191b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Traits/ShouldSnakeAttributes.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@
22

33
namespace Encore\Admin\Traits;
44

5+
use Encore\Admin\Grid\Model as GridModel;
6+
57
trait ShouldSnakeAttributes
68
{
9+
/**
10+
* Indicates whether attributes are snake cased on arrays.
11+
*
12+
* @var bool
13+
*/
14+
protected static $snakeAttributes;
15+
716
/**
817
* Indicates if model should snake attribute name.
918
*
1019
* @return bool
1120
*/
1221
public function shouldSnakeAttributes()
1322
{
14-
$class = get_class($this->model);
23+
if (is_bool(static::$snakeAttributes)) {
24+
return static::$snakeAttributes;
25+
}
26+
27+
$model = ($this->model instanceof GridModel) ?
28+
$this->model->eloquent() : $this->model;
29+
30+
$class = get_class($model);
1531

16-
return $class::$snakeAttributes;
32+
return static::$snakeAttributes = $class::$snakeAttributes;
1733
}
18-
}
34+
}

0 commit comments

Comments
 (0)