Skip to content

Commit 4468cb1

Browse files
authored
Merge pull request #15 from qcod/laravel-6
laravel 6 support closes #15
2 parents 57454e1 + 5551266 commit 4468cb1

19 files changed

+78
-70
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: php
22

33
php:
4-
- 7.1
4+
- 7.2
55

66
before_script:
77
- travis_retry composer self-update

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## 1.2.0 - 2019-09-05
6+
7+
- Laravel 6 support
8+
59
## 1.1.0 - 2019-08-14
610

711
- Group Settings by name

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=5.6.0",
25-
"laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0",
24+
"php": "^7.2",
25+
"laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0",
2626
"qcod/laravel-settings": "~1.0"
2727
},
2828
"require-dev": {
29-
"orchestra/testbench": "~3.4",
29+
"orchestra/testbench": "~3.4|^4.0",
3030
"mockery/mockery": "^0.9.4 || ~1.0",
31-
"phpunit/phpunit": "~7.0"
31+
"phpunit/phpunit": "~8.0"
3232
},
3333
"autoload": {
3434
"psr-4": {

src/Setting/AppSettings.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace QCod\AppSettings\Setting;
44

5+
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Str;
57
use Illuminate\Http\Request;
68
use Illuminate\Support\Facades\Storage;
79
use QCod\Settings\Setting\SettingStorage;
@@ -55,14 +57,14 @@ public function get($name, $default = null)
5557
// get the setting and fallback to default value from config
5658
$value = $this->settingStorage->get(
5759
$name,
58-
array_get($settingField, 'value', $default)
60+
Arr::get($settingField, 'value', $default)
5961
);
6062

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

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

@@ -79,12 +81,12 @@ public function get($name, $default = null)
7981
public function set($name, $value)
8082
{
8183
$settingField = $this->getSettingField($name);
82-
$dataType = array_get($settingField, 'data_type');
84+
$dataType = Arr::get($settingField, 'data_type');
8385

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

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

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

@@ -171,7 +173,7 @@ protected function getSettingUISections()
171173
public function getAllSettingFields()
172174
{
173175
return $this->getSettingUISections()->flatMap(function ($field) {
174-
return array_get($field, 'inputs', []);
176+
return Arr::get($field, 'inputs', []);
175177
});
176178
}
177179

@@ -185,7 +187,7 @@ public function getSettingField($name)
185187
{
186188
return $this->getAllSettingFields()
187189
->first(function ($field) use ($name) {
188-
return array_get($field, 'name') == $name;
190+
return Arr::get($field, 'name') == $name;
189191
}, []);
190192
}
191193

@@ -301,11 +303,11 @@ private function castToArray($value, $out)
301303
*/
302304
private function uploadFile($setting, $request)
303305
{
304-
$settingName = array_get($setting, 'name');
306+
$settingName = Arr::get($setting, 'name');
305307

306308
// get the disk and path to upload
307-
$disk = array_get($setting, 'disk', 'public');
308-
$path = array_get($setting, 'path', '/');
309+
$disk = Arr::get($setting, 'disk', 'public');
310+
$path = Arr::get($setting, 'path', '/');
309311

310312
$uploadedPath = null;
311313
$oldFile = $this->get($settingName);

src/helpers.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
*/
1212
function setting($key = null, $default = null)
1313
{
14+
$settings = app()->make('app-settings');
15+
1416
if (is_null($key)) {
15-
return app()->make('app-settings');
17+
return $settings;
1618
}
1719

1820
if (is_array($key)) {
19-
return app()->make('app-settings')->set($key);
21+
return $settings->set($key);
2022
}
2123

22-
return app()->make('app-settings')->get($key, value($default));
24+
return $settings->get($key, value($default));
2325
}
2426
}

src/resources/views/_settings.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

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

12-
@foreach(array_get($settingsUI, 'sections', []) as $section => $fields)
12+
@foreach(Arr::get($settingsUI, 'sections', []) as $section => $fields)
1313
@component('app_settings::section', compact('fields'))
14-
<div class="{{ array_get($fields, 'section_body_class', config('app_settings.section_body_class', 'card-body')) }}">
15-
@foreach(array_get($fields, 'inputs', []) as $field)
14+
<div class="{{ Arr::get($fields, 'section_body_class', config('app_settings.section_body_class', 'card-body')) }}">
15+
@foreach(Arr::get($fields, 'inputs', []) as $field)
1616
@if(!view()->exists('app_settings::fields.' . $field['type']))
1717
<div style="background-color: #f7ecb5; box-shadow: inset 2px 2px 7px #e0c492; border-radius: 0.3rem; padding: 1rem; margin-bottom: 1rem">
1818
Defined setting <strong>{{ $field['name'] }}</strong> with
@@ -30,7 +30,7 @@
3030
<div class="row m-b-md">
3131
<div class="col-md-12">
3232
<button class="btn-primary btn">
33-
{{ array_get($settingsUI, 'submit_btn_text', 'Save Settings') }}
33+
{{ Arr::get($settingsUI, 'submit_btn_text', 'Save Settings') }}
3434
</button>
3535
</div>
3636
</div>

src/resources/views/fields/_boolean_radio.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
id="{{ $field['name'] }}"
55
type="radio"
66
name="{{ $field['name'] }}"
7-
value="{{ array_get($field, 'true_value', '1') }}"
8-
@if(setting($field['name']) == array_get($field, 'true_value', '1')) checked @endif>
9-
{{ array_get($field, 'true_label', 'Yes') }}
7+
value="{{ Arr::get($field, 'true_value', '1') }}"
8+
@if(setting($field['name']) == Arr::get($field, 'true_value', '1')) checked @endif>
9+
{{ Arr::get($field, 'true_label', 'Yes') }}
1010
</label>
1111
</div>
1212
<div class="form-check form-check-inline">
1313
<label class="form-check-label">
1414
<input class="form-check-input"
1515
type="radio"
1616
name="{{ $field['name'] }}"
17-
value="{{ array_get($field, 'false_value', '0') }}"
18-
@if(setting($field['name']) == array_get($field, 'false_value', '0')) checked @endif>
19-
{{ array_get($field, 'false_label', 'No') }}
17+
value="{{ Arr::get($field, 'false_value', '0') }}"
18+
@if(setting($field['name']) == Arr::get($field, 'false_value', '0')) checked @endif>
19+
{{ Arr::get($field, 'false_label', 'No') }}
2020
</label>
2121
</div>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@if( $sub_title = array_get($field, 'sub_title'))
1+
@if( $sub_title = Arr::get($field, 'sub_title'))
22
<div class="row">
33
<div class="col-md-12">
44
<h4>{{ $sub_title }}</h4>
5-
@if($desc = array_get($field, 'desc'))
5+
@if($desc = Arr::get($field, 'desc'))
66
<p>{{ $desc }}</p>
77
@endif
88
</div>
99
</div>
10-
@endif
10+
@endif

src/resources/views/fields/_file.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
<br>
44
<input type="file"
55
name="{{ $field['name'] }}"
6-
@if( $placeholder = array_get($field, 'placeholder') )
6+
@if( $placeholder = Arr::get($field, 'placeholder') )
77
placeholder="{{ $placeholder }}"
88
@endif
9-
class="{{ array_get( $field, 'class') }} {{ $errors->has($field['name']) ? config('app_settings.input_invalid_class', 'is-invalid') : '' }}"
10-
@if( $styleAttr = array_get($field, 'style')) style="{{ $styleAttr }}" @endif
11-
id="{{ array_get($field, 'name') }}"
9+
class="{{ Arr::get( $field, 'class') }} {{ $errors->has($field['name']) ? config('app_settings.input_invalid_class', 'is-invalid') : '' }}"
10+
@if( $styleAttr = Arr::get($field, 'style')) style="{{ $styleAttr }}" @endif
11+
id="{{ Arr::get($field, 'name') }}"
1212
>
1313

1414
@if( $filePath = \setting($field['name']))
1515
<label class="text-danger" style="float:right; font-size: 0.8rem">
1616
<input type="checkbox" value="1" name="remove_file_{{$field['name']}}">
17-
{{ array_get($field, 'remove_label', 'Remove') }}
17+
{{ Arr::get($field, 'remove_label', 'Remove') }}
1818
</label>
19-
@php $fileUrl = \Storage::disk(array_get($field, 'disk', 'public'))->url($filePath) @endphp
19+
@php $fileUrl = \Storage::disk(Arr::get($field, 'disk', 'public'))->url($filePath) @endphp
2020
@if(in_array(pathinfo($filePath, PATHINFO_EXTENSION), ["gif", "jpg", "jpeg", "png", "tiff", "tif"]))
2121
<a href="{{ $fileUrl }}" target="_blank">
22-
<img src="{{ $fileUrl }}" alt="{{ $field['name'] }}" class="{{ array_get( $field, 'preview_class') }}" style="{{ array_get($field, 'preview_style') }}"/>
22+
<img src="{{ $fileUrl }}" alt="{{ $field['name'] }}" class="{{ Arr::get( $field, 'preview_class') }}" style="{{ Arr::get($field, 'preview_style') }}"/>
2323
</a>
2424
@else
2525
<a target="_blank" class="btn btn-light btn-sm" href="{{ $fileUrl }}">View {{ $field['label'] }}</a>

src/resources/views/fields/_hint.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@if($hint = array_get($field, 'hint'))
2-
<small class="{{ array_get($field, 'input_hint_class', config('app_settings.input_hint_class', '')) }}">
1+
@if($hint = Arr::get($field, 'hint'))
2+
<small class="{{ Arr::get($field, 'input_hint_class', config('app_settings.input_hint_class', '')) }}">
33
{{ $hint }}
44
</small>
55
@endif

0 commit comments

Comments
 (0)