Skip to content

Commit

Permalink
Merge pull request #2 from jameswagoner/bug/str-of-fix
Browse files Browse the repository at this point in the history
Laravel 6.x does not support Str::of()
  • Loading branch information
ChrisThompsonTLDR authored Jun 24, 2020
2 parents 9f184ab + 27a0b7b commit 95441ff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion resources/views/filters/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="form-group filter">
<div id="filter{{ Str::of($filter->field)->title() }}" class="checkbox">
<div id="filter{{ Str::title($filter->field) }}" class="checkbox">
<label>
{!! Form::checkbox('filter_' . $filter->field, isset($filter->value) ? $filter->value : true, isset($params['filter_' . $filter->field]) ? true : false) !!} {{ $filter->display }}
</label>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filters/datetime-range.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="form-group filter">
<div id="filter{{ Str::of($filter->field)->title() }}">
<div id="filter{{ Str::title($filter->field) }}">
@if(!isset($filter->label) || $filter->label === true)<div><strong>{!! $filter->display !!}</strong></div>@endif
{!! Form::text('filter_' . $filter->field . '_start', isset($params['filter_' . $filter->field . '_start']) ? $params['filter_' . $filter->field . '_start'] : null, ['class' => 'form-control']) !!}
to
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filters/input.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="form-group filter">
<div id="filter{{ Str::of($filter->field)->title() }}">
<div id="filter{{ Str::title($filter->field) }}">
@if(!isset($filter->label) || $filter->label === true)<div><strong>{!! $filter->display !!}</strong></div>@endif
{{ Form::text('filter[' . $filter->field . ']', isset($params['filter'][$filter->field]) ? $params['filter'][$filter->field] : null, ['class' => 'form-control']) }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filters/range.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="form-group filter">
<div id="filter{{ Str::of($filter->field)->title() }}">
<div id="filter{{ Str::title($filter->field) }}">
@if(!isset($filter->label) || $filter->label === true)<div><strong>{!! $filter->display !!}</strong></div>@endif
{!! Form::text('filter[' . $filter->field . '-start]', isset($params['filter'][$filter->field . '-start']) ? $params['filter'][$filter->field . '-start'] : null, ['class' => 'form-control']) !!}
to
Expand Down
2 changes: 1 addition & 1 deletion resources/views/filters/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="form-group filter">
<div id="filter{{ Str::of($filter->field)->title() }}">
<div id="filter{{ Str::title($filter->field) }}">
@if(!isset($filter->label) || $filter->label === true)<div><strong>{!! $filter->display !!}</strong></div>@endif
{!! Form::select('filter[' . $filter->field . ']', $filter->values, isset($params['filter'][$filter->field]) ? $params['filter'][$filter->field] : null, ['class' => 'form-control', 'placeholder' => isset($filter->placeholder) ? $filter->placeholder : '']) !!}
</div>
Expand Down
44 changes: 22 additions & 22 deletions src/Traits/LaramanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function startup()
$this->__configure();

if (empty($this->model)) {
$this->model = config('laraman.model_path') . Str::of(class_basename($this))->replace('Controller', '')->singular();
$this->model = config('laraman.model_path') . Str::singular(str_replace('Controller', '', class_basename($this)));
}

// turn on/off searching
Expand Down Expand Up @@ -126,12 +126,12 @@ public function index(Request $request)

// get the related model fields
$related = $columns->filter(function ($column) {
return Str::of($column['field'])->contains('.');
return Str::contains($column['field'], '.');
});

// remove related fields
$fields = $columns->filter(function ($column) {
return !Str::of($column['field'])->contains('.');
return !Str::contains($column['field'], '.');
});

// count fields to eager load
Expand Down Expand Up @@ -166,7 +166,7 @@ public function index(Request $request)
// we need a join
$relation = false;

if (Str::of($key)->contains('.')) {
if (Str::contains($key, '.')) {
$relation = true;

list($relatedModel, $rest) = explode('.', $key);
Expand All @@ -179,11 +179,11 @@ public function index(Request $request)
// this model
if (!$relation) {
// custom model filter
if (method_exists($builder->getModel(), 'filter' . Str::of($key)->studly())) {
$builder = $builder->getModel()->{'filter' . Str::of($key)->studly()}($builder, $val);
if (method_exists($builder->getModel(), 'filter' . Str::studly($key))) {
$builder = $builder->getModel()->{'filter' . Str::studly($key)}($builder, $val);
}
// ranges
elseif (Str::of($val)->contains(':')) {
elseif (Str::contains($val, ':')) {
list($start, $end) = explode(':', $val);

$start = urldecode($start);
Expand All @@ -209,11 +209,11 @@ public function index(Request $request)
// related model
else {
$builder->whereHas($relatedModel, function ($query) use ($rest, $val, $filter, &$appliedFilters) {
if (method_exists($query->getModel(), 'filter' . Str::of($rest)->studly())) {
$query->{'filter' . Str::of($rest)->studly()}($query, $val);
if (method_exists($query->getModel(), 'filter' . Str::studly($rest))) {
$query->{'filter' . Str::studly($rest)}($query, $val);
}
// ranges
elseif (Str::of($val)->contains(':')) {
elseif (Str::contains($val, '.')) {
list($start, $end) = explode(':', $val);

$start = urldecode($start);
Expand Down Expand Up @@ -255,15 +255,15 @@ public function index(Request $request)
}
}
$related->each(function ($row) use ($builder) {
if (!method_exists($builder->getModel(), 'filter' . Str::of($row['field'])->studly())) {
if (!method_exists($builder->getModel(), 'filter' . Str::studly($row['field']))) {
$pieces = array_slice(explode('.', $row['field']), 0, -1);

$builder->with(implode('.', $pieces));
}
});

// related model, laraman has to do the heavy lifting
if (Str::of($sort)->contains('.')) {
if (Str::contains($sort, '.')) {
list($relatedModel, $rest) = explode('.', $sort);

$builder->with($relatedModel);
Expand Down Expand Up @@ -315,7 +315,7 @@ public function index(Request $request)

$builder->chunk($this->chunk, function ($rows) use (&$tmpRows, $key, $sort, $counts, $related) {
$containsSort = false;
if (Str::of($sort)->contains('.')) {
if (Str::contains($sort, '.')) {
$containsSort = true;
}

Expand Down Expand Up @@ -396,7 +396,7 @@ public function index(Request $request)

// formatter is a string
if (is_string($column['formatter'])) {
$new[$column['field']] = $model::{'formatter' . Str::of($column['formatter'])->title()}($params);
$new[$column['field']] = $model::{'formatter' . Str::title($column['formatter'])}($params);
}
// formatter is function
else {
Expand All @@ -411,7 +411,7 @@ public function index(Request $request)
$new[$column['field']] = Arr::get($row, $column['field']);

if (!empty($column['formatter'])) {
$new[$column['field']] = $model::{'formatter' . Str::of($column['formatter'])->title()}([
$new[$column['field']] = $model::{'formatter' . Str::title($column['formatter'])}([
'value' => $new[$column['field']],
'column' => $column,
'row' => $row,
Expand All @@ -436,7 +436,7 @@ public function index(Request $request)
if ($column->field == 'id') {
$column->display = 'ID';
} else {
$column->display = Str::of($column->display)->title();
$column->display = Str::title($column->display);
}
}

Expand All @@ -454,7 +454,7 @@ public function index(Request $request)
if ($filter->field == 'id') {
$filter->display = 'ID';
} else {
$filter->display = Str::of($filter->field)->title();
$filter->display = Str::title($filter->field);
}
}

Expand Down Expand Up @@ -531,7 +531,7 @@ public function show($id)
$column = ['field' => $column];
}

return Str::of($column['field'])->contains('.');
return Str::contains($column['field'], '.');
});

// remove related fields
Expand All @@ -540,7 +540,7 @@ public function show($id)
$column = ['field' => $column];
}

return !Str::of($column['field'])->contains('.');
return !Str::contains($column['field'], '.');
});

$buttons = collect(isset($set['buttons']) && is_array($set['buttons']) ? $set['buttons'] : []);
Expand Down Expand Up @@ -568,7 +568,7 @@ public function show($id)

// formatter is a string
if (is_string($column['formatter'])) {
$new[$column['field']] = $model::{'formatter' . Str::of($column['formatter'])->title()}($params);
$new[$column['field']] = $model::{'formatter' . Str::title($column['formatter'])}($params);
}
// formatter is function
else {
Expand All @@ -583,7 +583,7 @@ public function show($id)
$new[$column['field']] = Arr::get($relatedRow, $column['field']);

if (!empty($column['formatter'])) {
$new[$column['field']] = $model::{'formatter' . Str::of($column['formatter'])->title()}([
$new[$column['field']] = $model::{'formatter' . Str::title($column['formatter'])}([
'value' => $new[$column['field']],
'column' => $column,
'row' => $relatedRow,
Expand Down Expand Up @@ -633,7 +633,7 @@ public function show($id)
if ($column->field == 'id') {
$column->display = 'ID';
} else {
$column->display = Str::of($column->field)->title();
$column->display = Str::title($column->field);
}
}

Expand Down

0 comments on commit 95441ff

Please sign in to comment.