-
Notifications
You must be signed in to change notification settings - Fork 17
Add option for a custom model callback #46
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
base: main
Are you sure you want to change the base?
Conversation
|
||
```php | ||
use DutchCodingCompany\FilamentDeveloperLogins\FilamentDeveloperLoginsPlugin; | ||
use Illuminate\Database\Eloquent\Builder;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Illuminate\Database\Eloquent\Builder;; | |
use Illuminate\Database\Eloquent\Builder; |
@@ -103,6 +103,27 @@ FilamentDeveloperLoginsPlugin::make() | |||
->modelClass(Admin::class) | |||
``` | |||
|
|||
### Override query | |||
|
|||
Default the plugin will retrieve the user by searching the provided model using the specified column. If you want to implement your own logic to retrieve the user, you can use the `modelCallback()` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default the plugin will retrieve the user by searching the provided model using the specified column. If you want to implement your own logic to retrieve the user, you can use the `modelCallback()` method. | |
By default the plugin will retrieve the user by searching the provided model using the specified column. If you want to implement your own logic to retrieve the user, you can use the `modelCallback()` method. |
### Override query | ||
|
||
Default the plugin will retrieve the user by searching the provided model using the specified column. If you want to implement your own logic to retrieve the user, you can use the `modelCallback()` method. | ||
This method accepts a closure and provides the plugin and should return an instance of `Illuminate\Database\Eloquent\Builder`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method accepts a closure and provides the plugin and should return an instance of `Illuminate\Database\Eloquent\Builder`. | |
This method accepts a closure. The closure should return an instance of `Illuminate\Database\Eloquent\Builder`. |
* @param string $credentials | ||
* @return Builder<\Illuminate\Database\Eloquent\Model&\Illuminate\Contracts\Auth\Authenticatable> | ||
*/ | ||
public function getModelCallback(self $plugin, string $credentials): Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't get the model callback, but the user query builder (via the model callback)
value: $this->modelCallback | ||
?? static fn (): Builder => (new ($plugin->getModelClass())) | ||
->where($plugin->getColumn(), $credentials), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value: $this->modelCallback
?? static fn (self $plugin, string $credentials): Builder => (new ($plugin->getModelClass()))->where($plugin->getColumn(), $credentials),
As discussed in #27.
This feature adds the option to override the default behavior of retrieving users from the database. For example, when using scopes that need to be removed when switching users.