- array/string Helpers: Laravel Convert old array and string helpers into their modern class-based methods.

-  Use Laravel Carbon: Laravel provides an Illuminate\Support\Carbon class which wraps the underlying Carbon class. By using this class, you gain access to some additional testing methods and create separation between your code and underlying dependencies.
This commit is contained in:
Arno Kaimbacher 2022-08-12 07:53:27 +00:00
parent 50ceeb193b
commit 7d1406ee5c
16 changed files with 18 additions and 17 deletions

View File

@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use \Exception; use \Exception;
// use Carbon\Carbon; // use Illuminate\Support\Carbon;
use \Illuminate\Support\Carbon; use \Illuminate\Support\Carbon;
class RequestController extends Controller class RequestController extends Controller

View File

@ -18,7 +18,7 @@ use App\Models\User;
use App\Rules\RdrFilesize; use App\Rules\RdrFilesize;
use App\Rules\RdrFiletypes; use App\Rules\RdrFiletypes;
// use Illuminate\View\View; // use Illuminate\View\View;
use Carbon\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;

View File

@ -82,7 +82,7 @@ class ReviewController extends Controller
$fieldval = $fieldValue->{$property_name}; $fieldval = $fieldValue->{$property_name};
$value = $value . $fieldName . ": " . $fieldval . "; "; $value = $value . $fieldName . ": " . $fieldval . "; ";
} }
} elseif ($fieldValue instanceof \Carbon\Carbon) { } elseif ($fieldValue instanceof \Illuminate\Support\Carbon) {
$value = $value . " Year " . $fieldValue->year; $value = $value . " Year " . $fieldValue->year;
$value = $value . " Month " . $fieldValue->month; $value = $value . " Month " . $fieldValue->month;
$value = $value . " Day " . $fieldValue->day; $value = $value . " Day " . $fieldValue->day;

View File

@ -1,7 +1,7 @@
<?php <?php
namespace App\Library\Util; namespace App\Library\Util;
use Carbon\Carbon; use Illuminate\Support\Carbon;
/** /**
* Describes local document as a match in context of a related search query. * Describes local document as a match in context of a related search query.

View File

@ -234,7 +234,7 @@ trait DatasetExtension
if (true === empty($fieldval)) { if (true === empty($fieldval)) {
$fieldval = null; $fieldval = null;
} else { } else {
$fieldval = new \Carbon\Carbon($fieldval); $fieldval = new \Illuminate\Support\Carbon($fieldval);
} }
} }

View File

@ -157,7 +157,7 @@ class Strategy
if ($value instanceof \Illuminate\Database\Eloquent\Model) { if ($value instanceof \Illuminate\Database\Eloquent\Model) {
$this->_mapModelAttributes($value, $dom, $childNode); $this->_mapModelAttributes($value, $dom, $childNode);
} elseif ($value instanceof \Carbon\Carbon) { } elseif ($value instanceof \Illuminate\Support\Carbon) {
$this->_mapDateAttributes($value, $dom, $childNode); $this->_mapDateAttributes($value, $dom, $childNode);
} elseif (is_array($value)) { } elseif (is_array($value)) {
$this->_mapArrayAttributes($value, $dom, $childNode); $this->_mapArrayAttributes($value, $dom, $childNode);
@ -181,7 +181,7 @@ class Strategy
return $dom->createElement($fieldName); return $dom->createElement($fieldName);
} }
protected function _mapDateAttributes(\Carbon\Carbon $model, DOMDocument $dom, \DOMNode $rootNode) protected function _mapDateAttributes(\Illuminate\Support\Carbon $model, DOMDocument $dom, \DOMNode $rootNode)
{ {
$rootNode->setAttribute("Year", $model->year); $rootNode->setAttribute("Year", $model->year);
$rootNode->setAttribute("Month", $model->month); $rootNode->setAttribute("Month", $model->month);

View File

@ -15,7 +15,7 @@ use App\Models\Title;
use App\Models\User; use App\Models\User;
use App\Models\XmlCache; use App\Models\XmlCache;
use App\Models\DatasetIdentifier; use App\Models\DatasetIdentifier;
use Carbon\Carbon; use Illuminate\Support\Carbon;
// use App\Models\GeolocationBox; // use App\Models\GeolocationBox;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;

View File

@ -2,6 +2,7 @@
namespace App\Rules; namespace App\Rules;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Validation\Rule; use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
@ -102,7 +103,7 @@ class RdrFilesize implements Rule
private function getSize($attribute, $value) private function getSize($attribute, $value)
{ {
if (is_numeric($value) && $hasNumeric) { if (is_numeric($value) && $hasNumeric) {
return array_get($this->data, $attribute); return Arr::get($this->data, $attribute);
} elseif (is_array($value)) { } elseif (is_array($value)) {
return count($value); return count($value);
} elseif ($value instanceof File) { } elseif ($value instanceof File) {

View File

@ -2,7 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
// use Carbon\Carbon; // use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
// use Carbon\Carbon; // use Illuminate\Support\Carbon;
// use Database\DisableForeignKeys; // use Database\DisableForeignKeys;
// use Database\TruncateTable; // use Database\TruncateTable;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use Carbon\Carbon; use Illuminate\Support\Carbon;
// use Database\DisableForeignKeys; // use Database\DisableForeignKeys;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use Carbon\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use Carbon\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use Carbon\Carbon; use Illuminate\Support\Carbon;
// use Database\DisableForeignKeys; // use Database\DisableForeignKeys;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;

View File

@ -93,7 +93,7 @@
{{-- <div class="form-group"> {{-- <div class="form-group">
{!! Form::label('licenses[]', 'Licenses..') !!} {!! Form::label('licenses[]', 'Licenses..') !!}
{!! Form::select('licenses[]', $options, array_pluck($document->licenses, 'id'), ['multiple' ]) !!} {!! Form::select('licenses[]', $options, Arr::pluck($document->licenses, 'id'), ['multiple' ]) !!}
</div> --}} </div> --}}
<div class="pure-control-group checkboxlist"> <div class="pure-control-group checkboxlist">

View File

@ -48,7 +48,7 @@
<td> <td>
{{-- @php {{-- @php
$dateDiff = $dataset['server_date_modified']->addDays(14); $dateDiff = $dataset['server_date_modified']->addDays(14);
$remainingDays = Carbon\Carbon::now()->diffInDays($dateDiff, false); $remainingDays = Illuminate\Support\Carbon::now()->diffInDays($dateDiff, false);
@endphp --}} @endphp --}}
{{ $dataset->remaining_time . ' days' }} {{ $dataset->remaining_time . ' days' }}