enhance components, add mailtemplate, add traits for translations, for stats
This commit is contained in:
26
app/Traits/HasTranslations.php
Normal file
26
app/Traits/HasTranslations.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Spatie\Translatable\HasTranslations as BaseHasTranslations;
|
||||
|
||||
trait HasTranslations
|
||||
{
|
||||
use BaseHasTranslations;
|
||||
|
||||
/**
|
||||
* Convert the model instance to an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$attributes = parent::toArray();
|
||||
foreach ($this->getTranslatableAttributes() as $field) {
|
||||
$attributes[$field] = $this->getTranslation($field, \App::getLocale());
|
||||
$attributes[$field.'_translations'] = $this->getTranslations($field);
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
13
app/Traits/StatHelpers.php
Normal file
13
app/Traits/StatHelpers.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait StatHelpers
|
||||
{
|
||||
public static function getLastValue()
|
||||
{
|
||||
$item = self::query()->start(now())->end(now()->subSecond())->groupByDay()->get();
|
||||
|
||||
return $item ? $item[0]->value : 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user