From 3ee2c1b0c20cc2bc05b5bc70f8637ee762e68a5b Mon Sep 17 00:00:00 2001 From: Aios Date: Sat, 11 Aug 2018 18:41:14 +0300 Subject: [PATCH 1/2] Fix NamedForm Element fixed #914 --- src/Form/Element/NamedFormElement.php | 84 ++++++++++++++------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/Form/Element/NamedFormElement.php b/src/Form/Element/NamedFormElement.php index 95b783038..be10f9b21 100644 --- a/src/Form/Element/NamedFormElement.php +++ b/src/Form/Element/NamedFormElement.php @@ -16,6 +16,7 @@ abstract class NamedFormElement extends FormElement { + use HtmlAttributes; /** * @var string @@ -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; @@ -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()); @@ -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); } @@ -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; } @@ -443,7 +446,7 @@ public function save(\Illuminate\Http\Request $request) } /** - * @param mixed $value + * @param mixed $value * * @return void */ @@ -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++; @@ -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; } @@ -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), ]); } } From 185ca9dec689eb77006278955e78dd8bb793853e Mon Sep 17 00:00:00 2001 From: Aios Date: Sun, 12 Aug 2018 14:49:56 +0300 Subject: [PATCH 2/2] New release 5.6 --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 997ca3c80..e7b0b78f9 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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)): @@ -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: @@ -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", ] ```