Skip to content

Commit

Permalink
Merge pull request #324 from lara-zeus/user-model
Browse files Browse the repository at this point in the history
feat: custom user model
  • Loading branch information
atmonshi authored Sep 1, 2024
2 parents 8e40c29 + 6821284 commit 2309d6c
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 167 deletions.
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

0 comments on commit 2309d6c

Please sign in to comment.