File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate \Database \Migrations \Migration ;
4+ use Illuminate \Database \Schema \Blueprint ;
5+ use Illuminate \Support \Facades \Schema ;
6+
7+ return new class extends Migration {
8+ public function up (): void
9+ {
10+ Schema::create ('pim_product_types ' , function (Blueprint $ table ) {
11+ $ table ->id ();
12+ $ table ->string ('name ' );
13+ $ table ->string ('code ' )->nullable ();
14+ $ table ->timestamps ();
15+ $ table ->softDeletes ();
16+ });
17+
18+ Schema::create ('pim_product_type_data ' , function (Blueprint $ table ) {
19+ $ table ->foreignId ('product_type_id ' )
20+ ->constrained ('pim_product_types ' )
21+ ->cascadeOnUpdate ()
22+ ->cascadeOnDelete ();
23+
24+ // Add foreign key for tenant if it's configured in the catalogue config
25+ if (config ('eclipse-catalogue.tenancy.model ' )) {
26+ $ tenantClass = config ('eclipse-catalogue.tenancy.model ' );
27+ /** @var \Illuminate\Database\Eloquent\Model $tenant */
28+ $ tenant = new $ tenantClass ;
29+ $ table ->foreignId (config ('eclipse-catalogue.tenancy.foreign_key ' ))
30+ ->constrained ($ tenant ->getTable (), $ tenant ->getKeyName ())
31+ ->cascadeOnUpdate ()
32+ ->cascadeOnDelete ();
33+ }
34+
35+ $ table ->boolean ('is_active ' )->default (true );
36+ $ table ->boolean ('is_default ' )->default (false );
37+ });
38+ }
39+
40+ public function down (): void
41+ {
42+ Schema::dropIfExists ('pim_product_type_data ' );
43+ Schema::dropIfExists ('pim_product_types ' );
44+ }
45+ };
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Eclipse \Catalogue \Models \Product ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Database \Eloquent \SoftDeletes ;
7+
8+ class Type extends Model
9+ {
10+ use SoftDeletes;
11+
12+ protected $ table = 'pim_product_types ' ;
13+
14+ protected $ fillable = [
15+ 'name ' ,
16+ 'code ' ,
17+ ];
18+ }
You can’t perform that action at this time.
0 commit comments