Last active
August 8, 2025 14:31
-
-
Save NandoKstroNet/f012e5d2153689d77e3efbc074a43f6d to your computer and use it in GitHub Desktop.
Migrations, FilamentPHP V4 Multi-Auth App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
trait AppAuthenticationRecoveryCodes | |
{ | |
/** | |
* @return ?array<string> | |
*/ | |
public function getAppAuthenticationRecoveryCodes(): ?array | |
{ | |
// This method should return the user's saved app authentication recovery codes. | |
return $this->app_authentication_recovery_codes; | |
} | |
/** | |
* @param array<string> | null $codes | |
*/ | |
public function saveAppAuthenticationRecoveryCodes(?array $codes): void | |
{ | |
// This method should save the user's app authentication recovery codes. | |
$this->app_authentication_recovery_codes = $codes; | |
$this->save(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
trait AppAuthenticationSecret | |
{ | |
public function getAppAuthenticationSecret(): ?string | |
{ | |
// This method should return the user's saved app authentication secret. | |
return $this->app_authentication_secret; | |
} | |
public function saveAppAuthenticationSecret(?string $secret): void | |
{ | |
// This method should save the user's app authentication secret. | |
$this->app_authentication_secret = $secret; | |
$this->save(); | |
} | |
public function getAppAuthenticationHolderName(): string | |
{ | |
// In a user's authentication app, each account can be represented by a "holder name". | |
// If the user has multiple accounts in your app, it might be a good idea to use | |
// their email address as then they are still uniquely identifiable. | |
return $this->email; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Run the migrations. | |
*/ | |
public function up(): void | |
{ | |
Schema::table('users', function (Blueprint $table) { | |
$table->text('app_authentication_secret')->nullable(); | |
$table->text('app_authentication_recovery_codes')->nullable(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
*/ | |
public function down(): void | |
{ | |
Schema::table('users', function (Blueprint $table) { | |
$table->dropColumn('app_authentication_secret'); | |
$table->dropColumn('app_authentication_recovery_codes'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment