laravel-nami-api/src/Activity.php

28 lines
606 B
PHP

<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
class Activity 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 subactivities() {
return Nami::subactivitiesOf($this->id);
}
}