PHP code example of sergkulich / laravel-key-rotate
1. Go to this page and download the library: Download sergkulich/laravel-key-rotate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sergkulich / laravel-key-rotate example snippets
namespace App\Providers;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
if (app()->runningInConsole()) {
// Subscribe The Listener to The Event
KeyRotate::withListener()
// Discover Models that are not in App\ namespace
->withDir(base_path('src/Domain'), 'Domain\\')
// Exclude Models
->withoutModel(User::class)
// Exclude Model Fields
->withoutModelFileds(Secret::class, ['secret'])
// Without Cast
->withoutCast('encrypted:array')
// With Custom Cast
->withCast(CustomCast::class);
}
}
}
namespace App\Providers;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
if (app()->runningInConsole()) {
KeyRotate::withListener();
}
}
}
// Get Instance
$listener = KeyRotate::getListener();
// Call it either
$listener();
// or
$listener->handle();