Files
cachet-docker/app/Bus/Handlers/Traits/StoresMeta.php
Nico Stapelbroek f4f77b1f1b Fix CodeStyle
2018-03-19 07:21:22 +01:00

49 lines
1021 B
PHP

<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Bus\Handlers\Traits;
use CachetHQ\Cachet\Models\Meta;
trait StoresMeta
{
/**
* Stores all Meta values of a model.
*
* @param $meta
* @param $type
* @param $id
*/
public function storeMeta($meta, $type, $id)
{
// Validation required instead of type hinting because it could be passed as false or NULL
if (!is_array($meta)) {
return;
}
foreach ($meta as $key => $value) {
if (empty($value)) {
continue;
}
$meta = Meta::firstOrNew([
'key' => $key,
'meta_type' => $type,
'meta_id' => $id,
]);
$meta->value = $value;
$meta->save();
}
}
}