for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Webfactor\Laravel\OpeningHours\Traits;
use Webfactor\Laravel\OpeningHours\Entities\OpeningHours;
use Webfactor\Laravel\OpeningHours\Entities\OpeningHoursForDay;
use Webfactor\Laravel\OpeningHours\Entities\TimeRange;
use Webfactor\Laravel\OpeningHours\Models\DayOpenTimeRange;
/** @property OpeningHours opening_hours */
trait HasOpeningHours
{
use OpeningHoursRelations;
public function getOpeningHoursAttribute()
$hours = $this->dayOpenTimeRanges
dayOpenTimeRanges
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
->groupBy('day')->map(function($day) {
return $day->map(function (DayOpenTimeRange $range) {
return $range->start.'-'.$range->end;
});
return OpeningHours::create($hours->toArray());
}
public function setOpeningHoursAttribute($data)
// clear previous open times
$this->dayOpenTimeRanges()->delete();
if ($data == null) {
return;
$rangesArray = collect($data->flatMap(function (OpeningHoursForDay $openingHoursForDay, string $day) {
return $openingHoursForDay->map(function (TimeRange $timeRange) use ($day) {
return [
'day' => $day,
'start' => $timeRange->start(),
'end' => $timeRange->end()
];
}))->map(function ($range) {
return new DayOpenTimeRange($range);
$this->dayOpenTimeRanges()->saveMany($rangesArray);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: