<分区>
在 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();
像上面那样使用静态函数不好吗?