1 | <?php |
||
9 | abstract class SqliteModel extends Model |
||
10 | { |
||
11 | /** |
||
12 | * $tableCreated. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected static $tableCreated = []; |
||
17 | |||
18 | /** |
||
19 | * Get the table associated with the model. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | 1 | public function getTable() |
|
27 | |||
28 | /** |
||
29 | * Resolve a connection instance. |
||
30 | * |
||
31 | * @param string|null $connection |
||
32 | * @return \Illuminate\Database\Connection |
||
33 | */ |
||
34 | 1 | public static function resolveConnection($connection = null) |
|
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | * |
||
42 | * @param string $table |
||
43 | * @return string |
||
44 | */ |
||
45 | 1 | protected function createTable($table) |
|
46 | { |
||
47 | 1 | if (isset(static::$tableCreated[$table]) === true) { |
|
48 | 1 | return $table; |
|
49 | } |
||
50 | |||
51 | $schema = $this->getConnection()->getSchemaBuilder(); |
||
52 | if ($schema->hasTable($table) === false) { |
||
53 | $schema->create($table, function (Blueprint $table) { |
||
54 | $this->createSchema($table); |
||
55 | }); |
||
56 | static::$tableCreated[$table] = true; |
||
57 | if ($this instanceof FileModel === true) { |
||
58 | $this->initializeTable($table); |
||
|
|||
59 | } |
||
60 | } |
||
61 | |||
62 | return $table; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * createSchema. |
||
67 | * |
||
68 | * @param Blueprint $table |
||
69 | * @return void |
||
70 | */ |
||
71 | abstract protected function createSchema(Blueprint $table); |
||
72 | } |
||
73 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: