Extracted title property to trait

This commit is contained in:
Andrés Santibáñez
2020-11-03 07:20:46 -05:00
parent 22b72c1980
commit 63fe7a1533
6 changed files with 43 additions and 57 deletions

39
src/Models/HasTitle.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
trait HasTitle
{
private $title;
public function setTitle($title)
{
$this->title = $title;
return $this;
}
protected function initTitle()
{
$this->title = $this->defaultTitle();
}
private function defaultTitle()
{
return '';
}
protected function titleFromArray($array)
{
$this->title = data_get($array, 'title', $this->defaultTitle());
}
protected function titleToArray()
{
return [
'title' => $this->title,
];
}
}