Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aios committed Aug 12, 2018
2 parents 9a31ef1 + 185ca9d commit 0e6109c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

## Laravel Admin Panel

[![Build Status](https://travis-ci.org/LaravelRUS/SleepingOwlAdmin.svg?branch=development)](https://travis-ci.org/LaravelRUS/SleepingOwlAdmin)
[![Build Status](https://travis-ci.org/LaravelRUS/SleepingOwlAdmin.svg?branch=master)](https://travis-ci.org/LaravelRUS/SleepingOwlAdmin)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/LaravelRUS/SleepingOwlAdmin/badges/quality-score.png?b=development)](https://scrutinizer-ci.com/g/LaravelRUS/SleepingOwlAdmin/?branch=development)
[![StyleCI](https://styleci.io/repos/52141393/shield?branch=development)](https://styleci.io/repos/52141393)
[![StyleCI](https://styleci.io/repos/52141393/shield?branch=master)](https://styleci.io/repos/52141393)
[![Laravel Support](https://img.shields.io/badge/Laravel-5.5--5.6-brightgreen.svg)]()
[![PHP Support](https://img.shields.io/badge/PHP-7.x-brightgreen.svg)]()
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/5906214c-a896-432c-ac24-b28144d6af1b/mini.png)](https://insight.sensiolabs.com/projects/5906214c-a896-432c-ac24-b28144d6af1b)

[![Official Site](https://img.shields.io/badge/official-site-blue.svg)](https://sleepingowl.ru)
[![Demo Site](https://img.shields.io/badge/demo-site-blue.svg)](https://demo.sleepingowl.ru)
Expand Down Expand Up @@ -35,7 +34,7 @@ SleepingOwl Admin is an administrative interface builder for Laravel.

1. Require this package in your composer.json and run composer update:

`composer require laravelrus/sleepingowl:4.x-new`
`composer require laravelrus/sleepingowl:5.6`


2. Run this command in the terminal (if you want to know more about what exactly this command does, see [install command documentation](https://en.sleepingowladmin.ru/docs/installation)):
Expand All @@ -50,7 +49,6 @@ SleepingOwl Admin is an administrative interface builder for Laravel.
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan sleepingowl:update",
"php artisan optimize",
]
```
__NOTE__: So if you use a laravel-ide-helper package place `sleepingowl:update` after it commands:
Expand All @@ -60,7 +58,6 @@ SleepingOwl Admin is an administrative interface builder for Laravel.
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan sleepingowl:update",
"php artisan optimize",
]
```
Expand Down
84 changes: 44 additions & 40 deletions src/Form/Element/NamedFormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

abstract class NamedFormElement extends FormElement
{

use HtmlAttributes;
/**
* @var string
Expand Down Expand Up @@ -303,9 +304,9 @@ public function getValidationRules()
*/
public function resolvePath()
{
$model = $this->getModel();
$model = $this->getModel();
$relations = explode('.', $this->getPath());
$count = count($relations);
$count = count($relations);

if ($count === 1) {
return $model;
Expand Down Expand Up @@ -362,16 +363,38 @@ public function getValueFromModel()
return $value;
}


$model = $this->getModel();
$path = $this->getPath();
$path = $this->getPath();
$value = $this->getDefaultValue();


/**
* Implement json parsing
*/
if (strpos($path, '->') !== false) {
$casts = collect($model->getCasts());
$jsonParts = collect(explode('->', $path));

$jsonAttr = $model->{$jsonParts->first()};

$cast = $casts->get($jsonParts->first(), false);

if ($cast == 'object') {
$jsonAttr = json_decode(json_encode($jsonAttr), true);
} elseif ($cast != 'array') {
$jsonAttr = json_decode($jsonAttr);
}

return Arr::get($jsonAttr, $jsonParts->slice(1)->implode('.'));
}

if (is_null($model) || ! $model->exists) {
return $value;
}

$relations = explode('.', $path);
$count = count($relations);
$count = count($relations);

if ($count === 1) {
$attribute = $model->getAttribute($this->getModelAttributeKey());
Expand All @@ -388,10 +411,10 @@ public function getValueFromModel()
}
if ($count === 2) {
if (str_contains($relation, '->')) {
$parts = explode('->', $relation);
$parts = explode('->', $relation);
$relationField = array_shift($array);
$jsonPath = implode('.', $parts);
$attribute = data_get($model->{$relationField}, $jsonPath);
$jsonPath = implode('.', $parts);
$attribute = data_get($model->{$relationField}, $jsonPath);
} else {
$attribute = $model->getAttribute($relation);
}
Expand All @@ -405,26 +428,6 @@ public function getValueFromModel()
}
}

/*
* Implement json parsing
*/
if (strpos($path, '->') !== false) {
$casts = collect($model->getCasts());
$jsonParts = collect(explode('->', $path));

$jsonAttr = $model->{$jsonParts->first()};

$cast = $casts->get($jsonParts->first(), false);

if ($cast == 'object') {
$jsonAttr = json_decode(json_encode($jsonAttr), true);
} elseif ($cast != 'array') {
$jsonAttr = json_decode($jsonAttr);
}

return Arr::get($jsonAttr, $jsonParts->slice(1)->implode('.'));
}

return $value;
}

Expand All @@ -443,7 +446,7 @@ public function save(\Illuminate\Http\Request $request)
}

/**
* @param mixed $value
* @param mixed $value
*
* @return void
*/
Expand Down Expand Up @@ -473,8 +476,8 @@ protected function getModelByPath($path)
$model = $this->getModel();

$relations = explode('.', $path);
$count = count($relations);
$i = 1;
$count = count($relations);
$i = 1;

if ($count > 1) {
$i++;
Expand All @@ -497,7 +500,8 @@ protected function getModelByPath($path)
case HasOne::class:
case MorphOne::class:
$relatedModel = $relationObject->getRelated()->newInstance();
$relatedModel->setAttribute($this->getForeignKeyNameFromRelation($relationObject), $relationObject->getParentKey());
$relatedModel->setAttribute($this->getForeignKeyNameFromRelation($relationObject),
$relationObject->getParentKey());
$model->setRelation($relation, $relatedModel);
break;
}
Expand Down Expand Up @@ -569,19 +573,19 @@ public function prepareValue($value)
public function toArray()
{
$this->setHtmlAttributes([
'id' => $this->getName(),
'id' => $this->getName(),
'name' => $this->getName(),
]);

return array_merge(parent::toArray(), [
'id' => $this->getName(),
'value' => $this->getValueFromModel(),
'name' => $this->getName(),
'path' => $this->getPath(),
'label' => $this->getLabel(),
'attributes'=> $this->htmlAttributesToString(),
'helpText' => $this->getHelpText(),
'required' => in_array('required', $this->validationRules),
'id' => $this->getName(),
'value' => $this->getValueFromModel(),
'name' => $this->getName(),
'path' => $this->getPath(),
'label' => $this->getLabel(),
'attributes' => $this->htmlAttributesToString(),
'helpText' => $this->getHelpText(),
'required' => in_array('required', $this->validationRules),
]);
}
}

0 comments on commit 0e6109c

Please sign in to comment.