Skip to content

Commit

Permalink
Use Cachet class to determine correct User model
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Jan 21, 2025
1 parent 028f9d3 commit 5cb444c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Cachet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Cachet;

use Cachet\Http\Middleware\RedirectIfAuthenticated;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand Down Expand Up @@ -34,6 +36,18 @@ public static function user(?Request $request = null)
return $request->user($guard);
}

/**
* Get the configured user model.
*
* @return Model<Authenticatable>
*/
public static function userModel(): Model

Check failure on line 44 in src/Cachet.php

View workflow job for this annotation

GitHub Actions / Static Analysis - P8.3 - L11.x - prefer-lowest

PHPDoc tag @return contains generic type Illuminate\Database\Eloquent\Model<Illuminate\Contracts\Auth\Authenticatable> but class Illuminate\Database\Eloquent\Model is not generic.

Check failure on line 44 in src/Cachet.php

View workflow job for this annotation

GitHub Actions / Static Analysis - P8.3 - L11.x - prefer-stable

PHPDoc tag @return contains generic type Illuminate\Database\Eloquent\Model<Illuminate\Contracts\Auth\Authenticatable> but class Illuminate\Database\Eloquent\Model is not generic.

Check failure on line 44 in src/Cachet.php

View workflow job for this annotation

GitHub Actions / Static Analysis - P8.2 - L11.x - prefer-lowest

PHPDoc tag @return contains generic type Illuminate\Database\Eloquent\Model<Illuminate\Contracts\Auth\Authenticatable> but class Illuminate\Database\Eloquent\Model is not generic.

Check failure on line 44 in src/Cachet.php

View workflow job for this annotation

GitHub Actions / Static Analysis - P8.2 - L11.x - prefer-stable

PHPDoc tag @return contains generic type Illuminate\Database\Eloquent\Model<Illuminate\Contracts\Auth\Authenticatable> but class Illuminate\Database\Eloquent\Model is not generic.
{
$userModel = config('cachet.user_model');

return new $userModel;
}

/**
* Register the Cachet routes.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/MakeUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cachet\Commands;

use Cachet\Cachet;
use Illuminate\Console\Command;

use function Laravel\Prompts\confirm;
Expand Down Expand Up @@ -121,7 +122,7 @@ protected function promptIsAdmin(): self
*/
protected function createUser(): void
{
$userModel = config('cachet.user_model');
$userModel = Cachet::userModel();

$userModel::create([
'name' => $this->data['name'],
Expand Down
3 changes: 2 additions & 1 deletion src/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cachet\Filament\Resources;

use Cachet\Cachet;
use Cachet\Filament\Resources\UserResource\Pages;
use Cachet\Models\User;
use Filament\Forms;
Expand Down Expand Up @@ -137,6 +138,6 @@ public static function getPluralLabel(): ?string

public static function getModel(): string
{
return config('cachet.user_model');
return Cachet::userModel()::class;
}
}

0 comments on commit 5cb444c

Please sign in to comment.