The solution suggested by @orest worked for me in the case of Notifications, but I tried it for reverting Http::fake() (using \Illuminate\Http\Client\Factory::class instead of ChannelManager::class) and it didn't seem to work. But I found this solution which worked for both.
I have read the source code a bit, the Notification::swap() method and the Illuminate\Support\Facades\Facade class.
All the mentioned solutions might work, but I believe this is the correct way to to get a real instance again:
use Illuminate\Support\Facades\Notification;
use Illuminate\Notifications\ChannelManager;
if (Notification::isFake()) {
$name = ChannelManager::class;
Notification::clearResolvedInstance($name);
Notification::getFacadeApplication()?->forgetInstance($name);
}
Ideally this should be a method of the Illuminate\Support\Facades\Facade class. I am thinking about contributing a real method to Laravel that do the same.
namespace Illuminate\Support\Facades\Facade;
abstract class Facade
{
public static function real(): void
{
if (static::isFake()) {
$name = static::getFacadeAccessor();
static::clearResolvedInstance($name);
static::$app?->forgetInstance($name);
}
}
}