Skip to content

Commit

Permalink
Merge pull request #15 from qcod/laravel-6
Browse files Browse the repository at this point in the history
laravel 6 support closes #15
  • Loading branch information
saqueib authored Sep 5, 2019
2 parents 57454e1 + 5551266 commit 4468cb1
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php

php:
- 7.1
- 7.2

before_script:
- travis_retry composer self-update
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `qcod/laravel-app-settings` will be documented in this file

## 1.2.0 - 2019-09-05

- Laravel 6 support

## 1.1.0 - 2019-08-14

- Group Settings by name
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
}
],
"require": {
"php": ">=5.6.0",
"laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0",
"php": "^7.2",
"laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0",
"qcod/laravel-settings": "~1.0"
},
"require-dev": {
"orchestra/testbench": "~3.4",
"orchestra/testbench": "~3.4|^4.0",
"mockery/mockery": "^0.9.4 || ~1.0",
"phpunit/phpunit": "~7.0"
"phpunit/phpunit": "~8.0"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 13 additions & 11 deletions src/Setting/AppSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace QCod\AppSettings\Setting;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use QCod\Settings\Setting\SettingStorage;
Expand Down Expand Up @@ -55,14 +57,14 @@ public function get($name, $default = null)
// get the setting and fallback to default value from config
$value = $this->settingStorage->get(
$name,
array_get($settingField, 'value', $default)
Arr::get($settingField, 'value', $default)
);

// cast the value
$outValue = $this->castValue(array_get($settingField, 'data_type'), $value, true);
$outValue = $this->castValue(Arr::get($settingField, 'data_type'), $value, true);

// check for accessor to run
if ($accessor = array_get($settingField, 'accessor')) {
if ($accessor = Arr::get($settingField, 'accessor')) {
$outValue = $this->runCallback($accessor, $name, $value);
}

Expand All @@ -79,12 +81,12 @@ public function get($name, $default = null)
public function set($name, $value)
{
$settingField = $this->getSettingField($name);
$dataType = array_get($settingField, 'data_type');
$dataType = Arr::get($settingField, 'data_type');

$val = $this->castValue($dataType, $value);

// check for mutator to run
if ($mutator = array_get($settingField, 'mutator')) {
if ($mutator = Arr::get($settingField, 'mutator')) {
$val = $this->runCallback($mutator, $name, $value);
}

Expand Down Expand Up @@ -142,7 +144,7 @@ public function loadConfig($config)
array_walk_recursive($config, function (&$value, $key) {
if (!in_array($key, ['mutator', 'accessor', 'rules']) && is_callable($value)) {
// skip any string which dont look like namesapce
if (is_string($value) && str_contains($value, '\\') == false) {
if (is_string($value) && Str::contains($value, '\\') == false) {
return;
}

Expand Down Expand Up @@ -171,7 +173,7 @@ protected function getSettingUISections()
public function getAllSettingFields()
{
return $this->getSettingUISections()->flatMap(function ($field) {
return array_get($field, 'inputs', []);
return Arr::get($field, 'inputs', []);
});
}

Expand All @@ -185,7 +187,7 @@ public function getSettingField($name)
{
return $this->getAllSettingFields()
->first(function ($field) use ($name) {
return array_get($field, 'name') == $name;
return Arr::get($field, 'name') == $name;
}, []);
}

Expand Down Expand Up @@ -301,11 +303,11 @@ private function castToArray($value, $out)
*/
private function uploadFile($setting, $request)
{
$settingName = array_get($setting, 'name');
$settingName = Arr::get($setting, 'name');

// get the disk and path to upload
$disk = array_get($setting, 'disk', 'public');
$path = array_get($setting, 'path', '/');
$disk = Arr::get($setting, 'disk', 'public');
$path = Arr::get($setting, 'path', '/');

$uploadedPath = null;
$oldFile = $this->get($settingName);
Expand Down
8 changes: 5 additions & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
*/
function setting($key = null, $default = null)
{
$settings = app()->make('app-settings');

if (is_null($key)) {
return app()->make('app-settings');
return $settings;
}

if (is_array($key)) {
return app()->make('app-settings')->set($key);
return $settings->set($key);
}

return app()->make('app-settings')->get($key, value($default));
return $settings->get($key, value($default));
}
}
8 changes: 4 additions & 4 deletions src/resources/views/_settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

@if( isset($settingsUI) && count($settingsUI) )

@foreach(array_get($settingsUI, 'sections', []) as $section => $fields)
@foreach(Arr::get($settingsUI, 'sections', []) as $section => $fields)
@component('app_settings::section', compact('fields'))
<div class="{{ array_get($fields, 'section_body_class', config('app_settings.section_body_class', 'card-body')) }}">
@foreach(array_get($fields, 'inputs', []) as $field)
<div class="{{ Arr::get($fields, 'section_body_class', config('app_settings.section_body_class', 'card-body')) }}">
@foreach(Arr::get($fields, 'inputs', []) as $field)
@if(!view()->exists('app_settings::fields.' . $field['type']))
<div style="background-color: #f7ecb5; box-shadow: inset 2px 2px 7px #e0c492; border-radius: 0.3rem; padding: 1rem; margin-bottom: 1rem">
Defined setting <strong>{{ $field['name'] }}</strong> with
Expand All @@ -30,7 +30,7 @@
<div class="row m-b-md">
<div class="col-md-12">
<button class="btn-primary btn">
{{ array_get($settingsUI, 'submit_btn_text', 'Save Settings') }}
{{ Arr::get($settingsUI, 'submit_btn_text', 'Save Settings') }}
</button>
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/resources/views/fields/_boolean_radio.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
id="{{ $field['name'] }}"
type="radio"
name="{{ $field['name'] }}"
value="{{ array_get($field, 'true_value', '1') }}"
@if(setting($field['name']) == array_get($field, 'true_value', '1')) checked @endif>
{{ array_get($field, 'true_label', 'Yes') }}
value="{{ Arr::get($field, 'true_value', '1') }}"
@if(setting($field['name']) == Arr::get($field, 'true_value', '1')) checked @endif>
{{ Arr::get($field, 'true_label', 'Yes') }}
</label>
</div>
<div class="form-check form-check-inline">
<label class="form-check-label">
<input class="form-check-input"
type="radio"
name="{{ $field['name'] }}"
value="{{ array_get($field, 'false_value', '0') }}"
@if(setting($field['name']) == array_get($field, 'false_value', '0')) checked @endif>
{{ array_get($field, 'false_label', 'No') }}
value="{{ Arr::get($field, 'false_value', '0') }}"
@if(setting($field['name']) == Arr::get($field, 'false_value', '0')) checked @endif>
{{ Arr::get($field, 'false_label', 'No') }}
</label>
</div>
6 changes: 3 additions & 3 deletions src/resources/views/fields/_description.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@if( $sub_title = array_get($field, 'sub_title'))
@if( $sub_title = Arr::get($field, 'sub_title'))
<div class="row">
<div class="col-md-12">
<h4>{{ $sub_title }}</h4>
@if($desc = array_get($field, 'desc'))
@if($desc = Arr::get($field, 'desc'))
<p>{{ $desc }}</p>
@endif
</div>
</div>
@endif
@endif
14 changes: 7 additions & 7 deletions src/resources/views/fields/_file.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
<br>
<input type="file"
name="{{ $field['name'] }}"
@if( $placeholder = array_get($field, 'placeholder') )
@if( $placeholder = Arr::get($field, 'placeholder') )
placeholder="{{ $placeholder }}"
@endif
class="{{ array_get( $field, 'class') }} {{ $errors->has($field['name']) ? config('app_settings.input_invalid_class', 'is-invalid') : '' }}"
@if( $styleAttr = array_get($field, 'style')) style="{{ $styleAttr }}" @endif
id="{{ array_get($field, 'name') }}"
class="{{ Arr::get( $field, 'class') }} {{ $errors->has($field['name']) ? config('app_settings.input_invalid_class', 'is-invalid') : '' }}"
@if( $styleAttr = Arr::get($field, 'style')) style="{{ $styleAttr }}" @endif
id="{{ Arr::get($field, 'name') }}"
>

@if( $filePath = \setting($field['name']))
<label class="text-danger" style="float:right; font-size: 0.8rem">
<input type="checkbox" value="1" name="remove_file_{{$field['name']}}">
{{ array_get($field, 'remove_label', 'Remove') }}
{{ Arr::get($field, 'remove_label', 'Remove') }}
</label>
@php $fileUrl = \Storage::disk(array_get($field, 'disk', 'public'))->url($filePath) @endphp
@php $fileUrl = \Storage::disk(Arr::get($field, 'disk', 'public'))->url($filePath) @endphp
@if(in_array(pathinfo($filePath, PATHINFO_EXTENSION), ["gif", "jpg", "jpeg", "png", "tiff", "tif"]))
<a href="{{ $fileUrl }}" target="_blank">
<img src="{{ $fileUrl }}" alt="{{ $field['name'] }}" class="{{ array_get( $field, 'preview_class') }}" style="{{ array_get($field, 'preview_style') }}"/>
<img src="{{ $fileUrl }}" alt="{{ $field['name'] }}" class="{{ Arr::get( $field, 'preview_class') }}" style="{{ Arr::get($field, 'preview_style') }}"/>
</a>
@else
<a target="_blank" class="btn btn-light btn-sm" href="{{ $fileUrl }}">View {{ $field['label'] }}</a>
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/fields/_hint.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if($hint = array_get($field, 'hint'))
<small class="{{ array_get($field, 'input_hint_class', config('app_settings.input_hint_class', '')) }}">
@if($hint = Arr::get($field, 'hint'))
<small class="{{ Arr::get($field, 'input_hint_class', config('app_settings.input_hint_class', '')) }}">
{{ $hint }}
</small>
@endif
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/fields/_label.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@if( $label = array_get($field, 'label') )
<label for="{{ array_get($field, 'name') }}">{{ $label }}</label>
@if( $label = Arr::get($field, 'label') )
<label for="{{ Arr::get($field, 'name') }}">{{ $label }}</label>
@endif
6 changes: 3 additions & 3 deletions src/resources/views/fields/_select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
@endphp

<select name="{{ $fieldName }}"
class="{{ array_get( $field, 'class', config('app_settings.input_class', 'form-control')) }}"
class="{{ Arr::get( $field, 'class', config('app_settings.input_class', 'form-control')) }}"
@if(isset($field['multi'])) multiple @endif
@if( $styleAttr = array_get($field, 'style')) style="{{ $styleAttr }}" @endif
@if( $styleAttr = Arr::get($field, 'style')) style="{{ $styleAttr }}" @endif
id="{{ $field['name'] }}">
@foreach(array_get($field, 'options', []) as $val => $label)
@foreach(Arr::get($field, 'options', []) as $val => $label)
<option value="{{ $val }}" @if( old($field['name'], \setting($field['name'])) == $val ) selected @endif>
{{ $label }}
</option>
Expand Down
14 changes: 7 additions & 7 deletions src/resources/views/fields/_text.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

<input type="{{ $field['type'] }}"
name="{{ $field['name'] }}"
@if( $placeholder = array_get($field, 'placeholder') )
@if( $placeholder = Arr::get($field, 'placeholder') )
placeholder="{{ $placeholder }}"
@endif
value="{{ old($field['name'], \setting($field['name'])) }}"
class="{{ array_get( $field, 'class', config('app_settings.input_class', 'form-control')) }} {{ $errors->has($field['name']) ? config('app_settings.input_invalid_class', 'is-invalid') : '' }}"
@if( $styleAttr = array_get($field, 'style')) style="{{ $styleAttr }}" @endif
@if( $maxAttr = array_get($field, 'max')) max="{{ $maxAttr }}" @endif
@if( $minAttr = array_get($field, 'min')) min="{{ $minAttr }}" @endif
id="{{ array_get($field, 'name') }}"
class="{{ Arr::get( $field, 'class', config('app_settings.input_class', 'form-control')) }} {{ $errors->has($field['name']) ? config('app_settings.input_invalid_class', 'is-invalid') : '' }}"
@if( $styleAttr = Arr::get($field, 'style')) style="{{ $styleAttr }}" @endif
@if( $maxAttr = Arr::get($field, 'max')) max="{{ $maxAttr }}" @endif
@if( $minAttr = Arr::get($field, 'min')) min="{{ $minAttr }}" @endif
id="{{ Arr::get($field, 'name') }}"
>

@if( $append = array_get($field, 'append'))
@if( $append = Arr::get($field, 'append'))
<span>{{ $append }}</span>
@endif

Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/fields/boolean.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@component('app_settings::input_group', compact('field'))
@if( count(array_get($field, 'options', [])) )
@if( count(Arr::get($field, 'options', [])) )
@include('app_settings::fields._select')
@else
<br>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/fields/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="form-group {{ $errors->has($field['name']) ? ' has-error' : '' }}">
<div class="checkbox">
<label>
<input name="{{ $field['name'] }}" value="{{ array_get($field, 'value', '1') }}" type="checkbox" @if(old($field['name'], \setting($field['name']))) checked="checked" @endif >
<input name="{{ $field['name'] }}" value="{{ Arr::get($field, 'value', '1') }}" type="checkbox" @if(old($field['name'], \setting($field['name']))) checked="checked" @endif >
{{ $field['label'] }}
</label>

Expand Down
6 changes: 3 additions & 3 deletions src/resources/views/fields/checkbox_group.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
@foreach($field['options'] as $option)
<div>
@php
$checkbox_value = array_get($option, 'value', $option, []);
$checkbox_label = array_get($option, 'label', $option, []);
$checkbox_value = Arr::get($option, 'value', $option, []);
$checkbox_label = Arr::get($option, 'label', $option, []);
$current_value = old($field['name'], \setting($field['name'], []));
@endphp
<label>
<input
@if( in_array($checkbox_value, $current_value)) checked @endif
name="{{ $field['name'] }}[]"
value="{{ $checkbox_value }}"
class="{{ array_get( $field, 'class') }}"
class="{{ Arr::get( $field, 'class') }}"
type="checkbox">
{{ $checkbox_label }}
</label>
Expand Down
12 changes: 6 additions & 6 deletions src/resources/views/fields/textarea.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

<textarea type="{{ $field['type'] }}"
name="{{ $field['name'] }}"
@if( $placeholder = array_get($field, 'placeholder') )
@if( $placeholder = Arr::get($field, 'placeholder') )
placeholder="{{ $placeholder }}"
@endif
@if( $rows = array_get($field, 'rows') )
@if( $rows = Arr::get($field, 'rows') )
rows="{{ $rows }}"
@endif
@if( $cols = array_get($field, 'cols') )
@if( $cols = Arr::get($field, 'cols') )
cols="{{ $cols }}"
@endif
class="{{ array_get( $field, 'class', config('app_settings.input_class', 'form-control')) }}"
@if( $styleAttr = array_get($field, 'style')) style="{{ $styleAttr }}" @endif
id="{{ array_get($field, 'name') }}"
class="{{ Arr::get( $field, 'class', config('app_settings.input_class', 'form-control')) }}"
@if( $styleAttr = Arr::get($field, 'style')) style="{{ $styleAttr }}" @endif
id="{{ Arr::get($field, 'name') }}"
>{{ old($field['name'], \setting($field['name'])) }}</textarea>

@endcomponent
2 changes: 1 addition & 1 deletion src/resources/views/input_group.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="{{ array_get( $field, 'input_wrapper_class', config('app_settings.input_wrapper_class', 'form-group')) }} {{ $errors->has($field['name']) ? array_get( $field, 'input_error_class', config('app_settings.input_error_class', 'has-danger')) : '' }}">
<div class="{{ Arr::get( $field, 'input_wrapper_class', config('app_settings.input_wrapper_class', 'form-group')) }} {{ $errors->has($field['name']) ? Arr::get( $field, 'input_error_class', config('app_settings.input_error_class', 'has-danger')) : '' }}">
@include('app_settings::fields._label')

{{ $slot }}
Expand Down
10 changes: 5 additions & 5 deletions src/resources/views/section.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="{{ array_get($fields, 'section_class', config('app_settings.section_class', 'card')) }} section-{{ str_slug($fields['title']) }}">
<div class="{{ array_get($fields, 'section_heading_class', config('app_settings.section_heading_class', 'card-header')) }}">
<i class="{{ array_get($fields, 'icon', 'glyphicon glyphicon-flash') }}"></i>
<div class="{{ Arr::get($fields, 'section_class', config('app_settings.section_class', 'card')) }} section-{{ Str::slug($fields['title']) }}">
<div class="{{ Arr::get($fields, 'section_heading_class', config('app_settings.section_heading_class', 'card-header')) }}">
<i class="{{ Arr::get($fields, 'icon', 'glyphicon glyphicon-flash') }}"></i>
{{ $fields['title'] }}
</div>

@if( $desc = array_get($fields, 'descriptions') )
<div class="pb-0 {{ config('app_settings.section_body_class', array_get($fields, 'section_body_class', 'card-body')) }}">
@if( $desc = Arr::get($fields, 'descriptions') )
<div class="pb-0 {{ config('app_settings.section_body_class', Arr::get($fields, 'section_body_class', 'card-body')) }}">
<p class="text-muted mb-0 ">{{ $desc }}</p>
</div>
@endif
Expand Down

0 comments on commit 4468cb1

Please sign in to comment.