Skip to content

Commit

Permalink
Convert auth() helper to use Auth facade (#1656)
Browse files Browse the repository at this point in the history
* Convert auth() helper to use Auth facade

* composer fix-style

---------

Co-authored-by: laravel-ide-helper <[email protected]>
  • Loading branch information
barryvdh and laravel-ide-helper authored Jan 8, 2025
1 parent 06c1fab commit 299a81b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/ide-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

'helper_files' => [
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
base_path() . '/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php',
],

/*
Expand Down
20 changes: 19 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function generate()
->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();
Expand Down Expand Up @@ -112,6 +112,24 @@ public function generateEloquent()
->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'));
Expand Down

0 comments on commit 299a81b

Please sign in to comment.