for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Rinvex\Support\Traits;
use DateTimeZone;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Date;
trait HasTimezones
{
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return \Illuminate\Support\Carbon
*/
protected function asDateTime($value)
$datetime = parent::asDateTime($value);
$timezone = optional(request()->user())->timezone;
if (! $timezone || $timezone === config('app.timezone')) {
return $datetime;
}
$thisIsUpdateRequest = Arr::first(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 30), function ($trace) {
debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 30)
array
object<Illuminate\Support\iterable>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
return $trace['function'] === 'setAttribute';
});
if ($thisIsUpdateRequest) {
// When updating attributes, we need to reset user timezone to system timezone before saving!
return Date::parse($datetime->toDateTimeString(), $timezone)->setTimezone(config('app.timezone'));
return $datetime->setTimezone(new DateTimeZone($timezone));
* Get a fresh timestamp for the model.
public function freshTimestamp()
$now = Date::now();
return (! $timezone || $timezone === config('app.timezone')) ? $now : $now->setTimezone($timezone);
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: