Php laravel中的时区()未知或错误
代码: 模型:company.phpPhp laravel中的时区()未知或错误,php,laravel,Php,Laravel,代码: 模型:company.php public function attendance() { $company = admin()->company; if ($company->office_start_time != NULL && $company->office_end_time != NULL) { $this->officeStartTime = $company->getOfficeStartTim
public function attendance()
{
$company = admin()->company;
if ($company->office_start_time != NULL && $company->office_end_time != NULL) {
$this->officeStartTime = $company->getOfficeStartTime()->timezone($company->timezone)->format('g:i A');
$this->officeEndTime = $company->getOfficeEndTime()->timezone($company->timezone)->format('g:i A');
}
return \View::make('admin.company_settings.attendance', $this->data);
}
这是因为在下面的行中
<?php
namespace App\Models;
use App\Observers\CompanyObserver;
use Carbon\Carbon;
use Laravel\Cashier\Billable;
class Company extends \Eloquent
{
use Billable;
protected $fillable = ['company_name','contact','address','name','email','country','timezone','logo','locale','billing_address','currency','currency_symbol'];
protected $dates = ['deleted_at', 'last_login', 'trial_ends_at', 'subscription_ends_at', 'licence_expire_on'];
protected $appends = ['logo_image_url'];
public function getTimezoneAttribute($value)
{
return explode("=", $value)[0];
}
public function getTimezoneIndexAttribute()
{
return explode("=", $this->attributes["timezone"])[1];
}
public function getOfficeEndTime(Carbon $date = null)
{
if ($date == null) {
$date = Carbon::now();
}
$dateStr = $date->format("Y-m-d");
$end = Carbon::createFromFormat("Y-m-d H:i:s", $dateStr . " " . $this->attributes["office_end_time"]);
$start = Carbon::createFromFormat("Y-m-d H:i:s", $dateStr . " " . $this->attributes["office_start_time"]);
if ($end < $start) {
$end->addDay();
}
return $end;
}
public function getOfficeStartTime(Carbon $date = null)
{
if ($date == null) {
$date = Carbon::now();
}
$dateStr = $date->format("Y-m-d");
$start = Carbon::createFromFormat("Y-m-d H:i:s", $dateStr . " " . $this->attributes["office_start_time"]);
return $start;
}
}
$company->timezone
公司的时区未设置或设置了错误的值
也
$company->timezone
的值是什么?它不显示任何内容“timezone”:“
@lagbox听起来不像有效的时区如何创建有效的时区@lagbox我们如何设置$company->timezone
@phpdroidy您必须有公司模型表,其中必须有此字段,可能在公司的设置中使用dd($company->timezone)在前面的行中。此停止执行并在()内显示值@KlintIf empty未设置…@phpdroid的响应也是正确的。您必须了解模型公司在字段timezone中的值为null或空的原因。。。
$this->officeStartTime = $company->getOfficeStartTime()->timezone($company->timezone)->format('g:i A');
$this->officeStartTime = $company->getOfficeStartTime()->timezone($company->timezone!=''?$company->timezone:'somehardcodedtimezone')->format('g:i A');