Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom user model #324

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
325 changes: 165 additions & 160 deletions composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/zeus-bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'FormsStatus' => \LaraZeus\Bolt\Models\FormsStatus::class,
'Response' => \LaraZeus\Bolt\Models\Response::class,
'Section' => \LaraZeus\Bolt\Models\Section::class,
'User' => config('auth.providers.users.model'),
],

'collectors' => [
Expand Down
16 changes: 16 additions & 0 deletions docs/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BoltPlugin::make()
'FormsStatus' => \App\Models\Bolt\FormsStatus::class,
'Response' => \App\Models\Bolt\Response::class,
'Section' => \App\Models\Bolt\Section::class,
'User' => \App\Models\Staff::class,
])

// make the actions floating in create and edit forms
Expand Down Expand Up @@ -104,3 +105,18 @@ to publish the configuration:
```bash
php artisan vendor:publish --tag=zeus-bolt-config
```

### Custom User Model:

By default Bolt will user this model to get the user info:

`config('auth.providers.users.model')`

if you need to change this to use another model, add the following in your config file: `zeus-bolt.php`:

```php
'models' => [
//...
'User' => AnotherUserModel::class,
],
```
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function getBoltModels(): array
return $this->boltModels;
}

public static function getModel(string $model): string
public static function getModel(string $model): ?string
{
return array_merge(
config('zeus-bolt.models'),
(new static)::get()->getBoltModels()
)[$model];
)[$model] ?? null;
}

public function navigationGroupLabel(Closure | string $label): static
Expand Down
5 changes: 4 additions & 1 deletion src/Filament/Exports/ResponseExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use Illuminate\Database\Eloquent\Model;
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Models\Field;
use LaraZeus\Bolt\Models\Response;

Expand All @@ -18,7 +19,9 @@ class ResponseExporter extends Exporter
public static function getColumns(): array
{
$record = \Livewire\Livewire::current()->getRecord();
$getUserModel = config('auth.providers.users.model')::getBoltUserFullNameAttribute();
//todo refactor with v4
$userModel = BoltPlugin::getModel('User') ?? config('auth.providers.users.model');
$getUserModel = $userModel::getBoltUserFullNameAttribute();
$mainColumns = [
ExportColumn::make('user.' . $getUserModel)
->label(__('Name'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class ManageResponses extends ManageRelatedRecords

public function table(Table $table): Table
{
$getUserModel = config('auth.providers.users.model')::getBoltUserFullNameAttribute();
//todo refactor with v4
$userModel = BoltPlugin::getModel('User') ?? config('auth.providers.users.model');
$getUserModel = $userModel::getBoltUserFullNameAttribute();

$mainColumns = [
ImageColumn::make('user.avatar')
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ protected static function newFactory(): Factory

public function user(): BelongsTo
{
return $this->belongsTo(config('auth.providers.users.model'));
return $this->belongsTo(config('zeus-bolt.models.User') ?? config('auth.providers.users.model'));
}
}
2 changes: 1 addition & 1 deletion src/Models/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected static function newFactory(): Factory

public function user(): BelongsTo
{
return $this->belongsTo(config('auth.providers.users.model'));
return $this->belongsTo(config('zeus-bolt.models.User') ?? config('auth.providers.users.model'));
}

/** @phpstan-return BelongsTo<Form, Category> */
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function fieldsResponses(): HasMany

public function user(): BelongsTo
{
return $this->belongsTo(config('auth.providers.users.model'));
return $this->belongsTo(config('zeus-bolt.models.User') ?? config('auth.providers.users.model'));
}

/** @return BelongsTo<Form, Response> */
Expand Down