You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+92-51Lines changed: 92 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Dynamic Model for Laravel!
1
+
# Dynamic Model for Laravel
2
2
3
3
[](https://packagist.org/packages/laracraft-tech/laravel-dynamic-model)
Schema::create('foo', function (Blueprint $table) {
48
48
$table->id();
49
49
$table->string('col1');
50
50
$table->integer('col2');
51
51
$table->timestamps();
52
52
});
53
-
...
53
+
54
+
Schema::create('bar', function (Blueprint $table) {
55
+
$table->date('period')->primary();
56
+
$table->string('col1');
57
+
$table->integer('col2');
58
+
$table->timestamps();
59
+
});
54
60
```
55
61
56
62
```bash
57
63
php artisan migrate
58
64
```
59
65
60
-
### Let's use the Dynamic Model:
61
-
**Note**: You could also use a different database connection.
62
-
Therefor just pass the `db_connection` as a second parameter.
66
+
### Let's create a Dynamic Model
63
67
64
-
Also be aware that the default DynamicModel is set to **unguarded**.
65
-
If you do not like this, check the section below and create your own dynamic model.
68
+
---
69
+
70
+
If you want to create a **Dynamic Model** then you have to use the **DynamicModelFactory**.
71
+
The Factory ensures, that the `table` and optionally the `connection` gets set for your new created model.
72
+
Also it checks the schema of your provided table to set the propper values for: `primaryKey`, `keyType`, `incrementing`.
73
+
Means, also if you defined your table schema to have a primary key called for instance __period__ with a __date__ type, the Factory will handle it for you.
74
+
75
+
Note that the default DynamicModel is set to **unguarded**.
76
+
If you do not like this or you want your Dynamic Models have some custom functions,
77
+
check the section below and create your own Dynamic Model.
66
78
67
79
```php
68
80
use LaracraftTech\LaravelDynamicModel\DynamicModel;
81
+
use LaracraftTech\LaravelDynamicModel\DynamicModelFactory;
0 commit comments