@@ -67,24 +67,24 @@ If you do not like this, check the section below and create your own dynamic mod
6767``` php
6868use LaracraftTech\LaravelDynamicModel\DynamicModel;
6969
70- $foo = App::make(DynamicModel::class, ['table_name' => ' foo']);
70+ $foo = App::make(DynamicModel::class, ['foo']);
7171
7272$foo->create([
7373 'col1' => 'asdf',
7474 'col2' => 123
7575]);
7676
77- $faz = App::make(DynamicModel::class, ['table_name' => ' faz']);
77+ $faz = App::make(DynamicModel::class, ['faz']);
7878$faz->create([...]);
7979
80- $bar = App::make(DynamicModel::class, ['table_name' => ' bar']);
80+ $bar = App::make(DynamicModel::class, ['bar']);
8181$bar->create([...]);
8282
83- $baz = App::make(DynamicModel::class, ['table_name' => ' baz']);
83+ $baz = App::make(DynamicModel::class, ['baz']);
8484$baz->create([...]);
8585
8686// use another db connection (this one must be defined in your config/database.php file)
87- $fooOtherDB = App::make(DynamicModel::class, ['table_name' => ' baz', 'db_connection' => ' your-db-connection-name-here']);
87+ $fooOtherDB = App::make(DynamicModel::class, ['baz', 'your-optional -db-connection-name-here']);
8888$fooOtherDB->create([...]);
8989
9090dd($foo->first());
@@ -113,15 +113,13 @@ you can just create your own Eloquent model and **extend** it by the **DynamicMo
113113or if the model is already extended by another model, you can just use the ** DynamicModelBinding** trait.
114114
115115If you use the trait, make sure your model implements the ** DynamicModelInterface** .
116- Also make sure to resolve these models through the ** DynamicModelFactory** and
117- call the ` bindDynamically ` function in the ` __constructor ` !
116+ Also make sure to always resolve these models through the container!
118117
119118``` php
120119namespace App\Models;
121120
122121use Illuminate\Database\Eloquent\Model;
123122use LaracraftTech\LaravelDynamicModel\DynamicModel;
124- use LaracraftTech\LaravelDynamicModel\DynamicModelFactory;
125123use LaracraftTech\LaravelDynamicModel\DynamicModelBinding;
126124use LaracraftTech\LaravelDynamicModel\DynamicModelInterface;
127125
@@ -141,22 +139,13 @@ class MyDynamicModel extends SomeBaseModel implements DynamicModelInterface
141139
142140 protected $guarded = [];
143141
144- // !!important!! call the parent constructor and bindDynamically function in the constructor!
145- public function __construct(array $attributes = [])
146- {
147- parent::__construct($attributes);
148-
149- $this->bindDynamically();
150- }
151-
152142 public function doSomething()
153143 {
154144 // do something
155145 }
156146}
157147
158- $foo = app(DynamicModelFactory::class)
159- ->create(MyDynamicModel::class, 'foo', 'optional-other-db-connection-name')
148+ $foo = app(MyDynamicModel::class, 'foo');
160149
161150$foo->create([
162151 'col1' => 'asdf',
0 commit comments