У меня есть Stat Класс:
class Stat extends Model
{
public static function getByKey($key)
{
return Stat::where("key", " = ", $key)->first();
}
public function getDates()
{
return json_decode($this->content);
}
}
В моей базе данных таблица stats содержит только два столбца (ключ, контент)
Когда я выполняю эту функцию, на мой взгляд, возникает ошибка
{!! \App\Stat::getByKey("ORDERS-DATA")->getDates() !!}
и это делает эту ошибку:
Exception message: Undefined property: App\Stat::$content
Поэтому я добавил эти две строки в getDates() для отладки ошибки:
public function getDates()
{
dd($this->content);//This shows the same error
dd($this->attributes["content"]);//This works fine and show me what I want
return json_decode($this->content);
}
затем я выполнил dd($this) и это показывает это:
Stat {#486
#connection: "mysql"
#table: "stats"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:5 [
"id" => 8
"key" => "ORDERS-DATA"
"content" => """
[
{
\t"day": "2019-04-01",
\t"count": "5"
}
]
"""
"created_at" => "2019-04-01 14:09:00"
"updated_at" => "2019-04-01 14:11:02"
]
#original: array:5 [
"id" => 8
"key" => "ORDERS-DATA"
"content" => """
[
{
\t"day": "2019-04-01",
\t"count": "5"
}
]
"""
"created_at" => "2019-04-01 14:09:00"
"updated_at" => "2019-04-01 14:11:02"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [
0 => "*"
]
}
И Чего я хочу, так это получить свой content по $this->content, и я не понимаю, почему это не работает??
Пожалуйста помоги






Ошибка возникает из-за того, что я переопределил одну из функций Laravel.
имя getDates ИЛИ getByKey ИЛИ getCounts используется Laravel.
This is so weird this error happened to me two times in the same day, Today's morning I created a function called
getAttributes()and showed me a total diferrent error. Why the community don't create a list of functions names that we are not allowed to use, or use more unique names ???