22
33declare (strict_types=1 );
44
5+ use GeneaLabs \LaravelGovernor \Team ;
56use Illuminate \Database \Migrations \Migration ;
67use Illuminate \Database \Schema \Blueprint ;
78
89class CreateGovernorTeamsTable extends Migration
910{
11+ protected $ userInstance ;
12+
1013 public function __construct ()
1114 {
1215 if (app ()->bound ("Hyn\Tenancy\Environment " )) {
1316 $ this ->connection = config ("tenancy.db.tenant-connection-name " );
1417 }
18+
19+ $ this ->userInstance = app (config ('genealabs-laravel-governor.models.auth ' ));
1520 }
1621
1722 public function up (): void
1823 {
1924 Schema::create ('governor_teams ' , function (Blueprint $ table ): void {
20- $ user = app (config ('genealabs-laravel-governor.models.auth ' ));
2125 $ table ->bigIncrements ("id " );
2226 $ table ->unsignedBigInteger ("governor_owned_by " )
2327 ->nullable ();
@@ -29,11 +33,19 @@ public function up(): void
2933 ->nullable ();
3034
3135 $ table ->foreign ('governor_owned_by ' )
32- ->references ($ user ->getKeyName ())
33- ->on ($ user ->getTable ())
36+ ->references ($ this -> userInstance ->getKeyName ())
37+ ->on ($ this -> userInstance ->getTable ())
3438 ->onDelete ('SET NULL ' )
3539 ->onUpdate ('CASCADE ' );
3640 });
41+
42+ Schema::table ($ this ->userInstance ->getTable (), function (Blueprint $ table ): void {
43+ $ table ->foreignIdFor (Team::class, "current_team_id " )
44+ ->nullable ()
45+ ->constrained ()
46+ ->cascadeOnDelete ()
47+ ->cascadeOnUpdate ();
48+ });
3749 }
3850
3951 public function down (): void
0 commit comments