how to get maximum value from casts object field in laravel eloquent model

Viewed 160

My model

class Applicant extends Model {

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

    protected $table = 'applicants';

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

records stored in application_no, Key could be increase ... [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,
    }

Now i want to get the maximum application_no of A or B ..... wise...

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