File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 27
27
],
28
28
"require" : {
29
29
"php" : " ^7.4|^8.0" ,
30
+ "haruncpi/laravel-id-generator" : " ^1.0" ,
30
31
"illuminate/console" : " ^8.0" ,
31
32
"illuminate/container" : " ^8.0" ,
32
33
"illuminate/contracts" : " ^8.0" ,
Original file line number Diff line number Diff line change 2
2
3
3
namespace Bssd \EloquentRepository \Repository \Concerns ;
4
4
5
+ use Haruncpi \LaravelIdGenerator \IdGenerator ;
5
6
use Illuminate \Database \Eloquent \Builder ;
6
7
use Illuminate \Database \Eloquent \Model ;
8
+ use Illuminate \Support \Facades \DB ;
7
9
8
10
/**
9
11
* @property-read Builder|Model $model
@@ -22,4 +24,35 @@ public function create($properties)
22
24
{
23
25
return $ this ->model ->create ($ properties );
24
26
}
27
+
28
+ /**
29
+ * Get next auto increment ID
30
+ *
31
+ * @return int
32
+ */
33
+ public function getAutoIncrementedId (): int
34
+ {
35
+ $ inspector = DB ::select ("SHOW TABLE STATUS LIKE ' " .$ this ->model ->getTable ()."' " );
36
+ return $ inspector [0 ]->Auto_increment ;
37
+ }
38
+
39
+ /**
40
+ * Get next customized ID
41
+ *
42
+ * @param string $field
43
+ * @param int $length
44
+ * @param string $prefix
45
+ *
46
+ * @return string
47
+ * @throws \Exception
48
+ */
49
+ public function getCustomizedId (string $ field , int $ length , string $ prefix ): string
50
+ {
51
+ return IdGenerator::generate ([
52
+ 'table ' => $ this ->model ->getTable (),
53
+ 'field ' => $ field ,
54
+ 'length ' => $ length ,
55
+ 'prefix ' => $ prefix
56
+ ]);
57
+ }
25
58
}
You can’t perform that action at this time.
0 commit comments