如何在laravel eloquent模型中从casts对象字段中获取最大值

时间:2017-08-16 11:07:19

标签: laravel-5.4 laravel-eloquent

我的模特

class Applicant extends Model {

    protected $dates = [ 'date_of_birth', 'sent_by_post_date' ];

    protected $table = 'applicants';

    protected $casts = [ 'application_no' => 'object' ];
}

存储在application_no中的记录,密钥可能会增加... [A,B,C,D,.....]

1. {
    "A" : 1,
    "C" : 1,
    }
2. {
    "A" : 2,
    "B" : 1,
    }
3. {
    "A" : 3,
    "B" : 2,
    }
4. {
    "A" : 4,
    "B" : 3,
    }
5. {
    "A" : 5,
    "C" : 2,
    "D" : 1,
    }

现在我希望得到AB的最大application_no .....明智......

public function getMaximumApplicationNo($shortCode){
    return Applicant::max("application_no.$shortCode" );
}

0 个答案:

没有答案