Skip to content

Commit

Permalink
helpers function created, some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dobrik committed Jun 12, 2019
1 parent 2fa3569 commit 83a2861
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
}
],
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Dobrik\\LaravelEasyForm\\": "src/"
}
Expand Down
3 changes: 2 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Dobrik\LaravelEasyForm\Forms\HtmlAbstract;
use Dobrik\LaravelEasyForm\Exceptions\InvalidAliasException;
use Dobrik\LaravelEasyForm\Forms\Interfaces\PluginInterface;

Expand Down Expand Up @@ -37,7 +38,7 @@ class Factory

public function __construct(array $aliases = [])
{
$this->aliases = array_merge($this->aliases, $aliases);
$this->aliases = array_merge_recursive($this->aliases, $aliases);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Forms/HtmlAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dobrik\LaravelEasyForm\Forms;

use Dobrik\LaravelEasyForm\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -123,9 +124,10 @@ protected function getView($data = []): string
$class_name = get_class($this);
$class_name_array = explode('\\', $class_name);
$class_name_array = \array_slice($class_name_array, -2);
$template = 'creator';
foreach ($class_name_array as $item) {
$template .= '.' . strtolower(Str::snake($item, '_'));
$template = 'easy_form::';
foreach ($class_name_array as $key => $item) {
$template .= $key === 0?'':'.';
$template .= strtolower(Str::snake($item, '_'));
}

if (view()->exists($template)) {
Expand Down
17 changes: 17 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

if (!function_exists('arrayToDot')) {
/**
* Change input name from array style to dot notation style
* @param string $name
* @return string
*/
function arrayToDot(string $name)
{
if (\Illuminate\Support\Str::contains($name, '[') && \Illuminate\Support\Str::contains($name, ']')) {
$name = str_replace(array(']', '['), array('', '.'), $name);
}

return $name;
}
}

0 comments on commit 83a2861

Please sign in to comment.