laravel-nami-api/src/Confession.php

26 lines
525 B
PHP
Raw Normal View History

2020-06-30 00:01:17 +02:00
<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Database\Eloquent\Model;
2022-03-11 20:20:00 +01:00
class Confession extends Model
{
2020-06-30 00:01:17 +02:00
protected $guarded = [];
2022-03-11 20:20:00 +01:00
public static function fromNami($item)
{
2020-06-30 00:01:17 +02:00
$item = collect($item)
->only(['descriptor', 'id'])
2022-03-11 20:20:00 +01:00
->mapWithKeys(function ($item, $key) {
if ('id' == $key) {
return ['id' => $item];
}
2020-06-30 00:01:17 +02:00
return ['name' => $item];
})->toArray();
2022-03-11 20:20:00 +01:00
return new self($item);
2020-06-30 00:01:17 +02:00
}
}