public function make($data)
{
if ($data instanceof Collection) {
$this->data = collect($data->toArray());
} elseif (is_array($data)) {
$this->data = collect($data);
} else {
throw new InvalidArgumentException('Invalid data type.');
}
$this->config = Config::get('nestable');
$this->parent = $this->config['parent'];
$this->primary_key = $this->config['primary_key'];
return $this;
}
/** * Pass data to nest methods. * * @return mixed */ protected function to() { if (static::$to === 1) { $method = 'renderAsArray'; } elseif (static::$to === 2) { $method = 'renderAsJson'; } elseif (static::$to === 3) { $method = 'renderAsHtml'; } elseif (static::$to === 4) { $method = 'renderAsDropdown'; } else { return $this->source; } $nest = new NestableService(); $nest->save(static::$parameters); $nestable = $nest->make($this->source); static::$nested = false; return call_user_func([$nestable, $method]); }