下面提到的代码工作正常,但我想从数据库设置public static $averageEvaluationCount = 3;
,以便我可以动态更改$averageEvaluationCount
。
<?php
namespace App\Models;
use DateTime;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class Post extends BaseDBModel
{
public function __construct()
{
$evalCountQuery = DB::table('averageEvaluations')->select('times')->get();
$evalCounts = $evalCountQuery[0]->times;
}
public static $x = 3;
protected $table = 'posts';
public static $pointsPerKool = 10;
public static $averageEvaluationValue = 8;
public static $averageEvaluationCount = 3; //I want to change this value 3 to a value from database $evalCounts
protected static $intervalForRedPoint = 1;
public static $commentRequiredLowThreshold = 10;
protected static $intervalForBluePoint = 3;
protected static $rateThresholdToMarkAsGoldWithK = 8;
protected static $daysToFreeze = 4320;
}
答案 0 :(得分:1)
public function __construct()
{
$evalCountQuery = DB::table('averageEvaluations')
->select('times')->get();
self::$averageEvaluationCount = $evalCountQuery[0]->times;
}
OR
public function __construct()
{
self::$averageEvaluationCount = DB::table('averageEvaluations')
->select('times')
->first()
->times;
}