laravel-nami-api/src/Subactivity.php

32 lines
728 B
PHP
Raw Normal View History

2020-07-04 21:23:10 +02:00
<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
class Subactivity extends Model {
protected $guarded = [];
public static function fromNami($item) {
$item = collect($item)
->only(['descriptor', 'id'])
->mapWithKeys(function($item,$key) {
if ($key == 'id') { return ['id' => $item]; }
return ['name' => $item];
})->toArray();
return (new self($item));
}
public function getNameAttribute() {
return ucfirst($this->attributes['name']);
}
public function getIsNullAttribute() {
return $this->attributes['id'] == self::getNullValue();
}
}