我的数据库中有一个表,其中有一个名为圆形的字段,记录如下
等
但是当我用orderBy ('round')订购的时候,我就这样把它们送回来了
我需要连续的
发布于 2020-02-27 20:33:47
您的列是基于文本的,因此按字母排序,而不是数字排序。将数据库列分成两部分:
$table->string('round'); // e.g. "Semifinals", "Regular Season"
$table->integer('round_number'); // e.g. 1, 2, 3, ... , 10然后你就可以做->orderBy('round', 'asc')->orderBy('round_number', 'asc');了
发布于 2020-02-27 18:28:27
您可以将round存储为有符号整数列,而不是在DB中存储字符串:
$table->integer('round');
$table->string('type');现在,您可以使用orderBy('round')来获得所需的结果。
您还可以在您的round模型上使用如下所示的round:
/**
* Get the formatted round value.
*
* @return string
*/
public function getRoundAttribute($value)
{
return "{$this->type} {$value}";
}https://stackoverflow.com/questions/60439459
复制相似问题