1 | <?php |
||
2 | |||
3 | namespace Jidaikobo\Kontiki\Models; |
||
4 | |||
5 | use Illuminate\Database\Connection; |
||
6 | use Illuminate\Database\Query\Builder; |
||
7 | use Jidaikobo\Kontiki\Core\Database; |
||
8 | use Jidaikobo\Kontiki\Models\BaseModelTraits; |
||
9 | use Jidaikobo\Kontiki\Services\ValidationService; |
||
10 | |||
11 | /** |
||
12 | * BaseModel provides common CRUD operations for database interactions. |
||
13 | * Extend this class to create specific models for different database tables. |
||
14 | */ |
||
15 | abstract class BaseModel implements ModelInterface |
||
16 | { |
||
17 | use BaseModelTraits\FieldDefinitionTrait; |
||
18 | use BaseModelTraits\SearchTrait; |
||
19 | use BaseModelTraits\UtilsTrait; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
20 | |||
21 | protected string $table; |
||
22 | protected string $postType = ''; |
||
23 | protected string $deleteType = 'hardDelete'; |
||
24 | protected Connection $db; |
||
25 | public ValidationService $validator; |
||
26 | |||
27 | public function __construct( |
||
28 | Database $db, |
||
29 | ValidationService $validator, |
||
30 | ) { |
||
31 | $this->db = $db->getConnection(); |
||
32 | $this->validator = $validator; |
||
33 | $this->validator->setModel($this); |
||
34 | $this->initializeFields(); |
||
35 | $this->initializeMetaDataFields(); |
||
36 | } |
||
37 | |||
38 | public function getQuery(): Builder |
||
39 | { |
||
40 | return $this->db->table($this->table); |
||
41 | } |
||
42 | |||
43 | public function getDeleteType(): string |
||
44 | { |
||
45 | return $this->deleteType; |
||
46 | } |
||
47 | |||
48 | public function getTableName(): string |
||
49 | { |
||
50 | return $this->table; |
||
51 | } |
||
52 | |||
53 | public function getPostType(): string |
||
54 | { |
||
55 | return $this->postType; |
||
56 | } |
||
57 | |||
58 | public function validate( |
||
59 | array $data, |
||
60 | array $context |
||
61 | ): array { |
||
62 | return $this->validator->validate($data, $context); |
||
63 | } |
||
64 | } |
||
65 |