From 299a81b9bb71e0b7e79f4bdd2a61e8c149fdeb1a Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 8 Jan 2025 13:50:47 +0100 Subject: [PATCH] Convert auth() helper to use Auth facade (#1656) * Convert auth() helper to use Auth facade * composer fix-style --------- Co-authored-by: laravel-ide-helper --- config/ide-helper.php | 1 + src/Generator.php | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config/ide-helper.php b/config/ide-helper.php index efcb0ee..1500783 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -123,6 +123,7 @@ return [ 'helper_files' => [ base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php', + base_path() . '/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php', ], /* diff --git a/src/Generator.php b/src/Generator.php index 78607b6..dc312f2 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -80,7 +80,7 @@ class Generator ->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace()) ->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace()) ->with('real_time_facades', $this->getRealTimeFacades()) - ->with('helpers', $this->helpers) + ->with('helpers', $this->detectHelpers()) ->with('include_fluent', $this->config->get('ide-helper.include_fluent', true)) ->with('factories', $this->config->get('ide-helper.include_factory_builders') ? Factories::all() : []) ->render(); @@ -112,6 +112,24 @@ class Generator ->render(); } + protected function detectHelpers() + { + $helpers = $this->helpers; + + $replacements = [ + '($guard is null ? \Illuminate\Contracts\Auth\Factory : \Illuminate\Contracts\Auth\StatefulGuard)' => '\\Auth', + ]; + foreach ($replacements as $search => $replace) { + $helpers = Str::replace( + "@return {$search}", + "@return $replace|$search", + $helpers + ); + } + + return $helpers; + } + protected function detectDrivers() { $defaultUserModel = config('auth.providers.users.model', config('auth.model', 'App\User'));