gpt4 book ai didi

php - Laravel 在 Controller 中使用公共(public)静态函数是不是很糟糕

转载 作者:行者123 更新时间:2023-12-05 05:26:08 27 4
gpt4 key购买 nike

<分区>

在 laravel Controller 中使用 public static 函数不好吗

在我的产品模型中,我有一个如下所示的函数:

public static function setEndDate($time)
{
if ($time == 2)
{
return Carbon::now()->addMonths(2)->toDateTimeString();
}
else
{
return Carbon::now()->addDays($time)->toDateTimeString();
}

}

然后在我的 Controller 中,我像这样使用该函数:

//Validation etc..

$time = Input::get('end_date'); //To transform end-time

$newProduct = new Product();

$newProduct->some_value = Input::get('some_value');
$newProduct->some_value = Input::get('some_value');


$newProduct->end_date = Product::setEndDate($time); //Using my static function like this


newProduct->save();

像上面那样使用静态函数不好吗?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com