-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathCaseNumber.php
More file actions
36 lines (30 loc) · 919 Bytes
/
CaseNumber.php
File metadata and controls
36 lines (30 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Class to generate a case number.
*
* For example to generate a unique id for a process request that is a parent process
* and non system. E.g.
*
* $sequence = CaseNumber::generate($request->id);
*/
class CaseNumber extends Model
{
use HasFactory;
protected $fillable = ['process_request_id'];
/**
* Generate a unique sequence for a given name.
*
* @param int|string $id of the request
* @return int The next value in the sequence.
*/
public static function generate($requestId): int
{
// Create a new sequence with the given name
$sequence = self::create(['process_request_id' => $requestId]);
// Return the id of the sequence as the next value in the sequence
return $sequence->id;
}
}