You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can create Custom User Provider to authenticate with DynamoDB. For the detail, please refer to [Laravel's official document](https://laravel.com/docs/6.x/authentication#adding-custom-user-providers).
293
+
`Kitar\Dynamodb\Model\Model` is a experimental Model implementation for this package.
294
+
295
+
It works like Eloquent Model, but there is no model querying features. Model's features to interact DynamoDB is only `save`, `update` and `delete`.
294
296
295
-
The Following codes are an example of custom user provider. It's simplified and not tested, so **don't use them in production**.
297
+
Instead we don't have model query, we'll tell the QueryBuilder to instantiate DynamoDB response with the specified model.
296
298
297
-
### Make User model
299
+
### Binding model to the QueryBuilder
298
300
299
-
To bind with authentication, we need to prepare User model which implements `Illuminate\Contracts\Auth\Authenticatable`.
301
+
For example, we have some user model below.
300
302
301
303
```php
304
+
<?php
305
+
302
306
namespace App;
303
307
304
-
use Illuminate\Support\Facades\DB;
305
-
use Illuminate\Contracts\Auth\Authenticatable as AuthAuthenticatable;
308
+
use Kitar\Dynamodb\Model\Model;
309
+
use Illuminate\Auth\Authenticatable;
310
+
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
306
311
307
-
class User implements AuthAuthenticatable
312
+
class User extends Model implements AuthenticatableContract
308
313
{
309
-
protected $params;
310
-
311
-
public function __construct($params)
312
-
{
313
-
$this->params = collect($params);
314
-
}
315
-
316
-
public function __get($name)
317
-
{
318
-
return $this->params[$name] ?? null;
319
-
}
314
+
use Authenticatable;
320
315
321
316
/**
322
-
* Get the name of the unique identifier for the user.
317
+
* The table associated with the model.
323
318
*
324
-
* @return string
319
+
* @var string
325
320
*/
326
-
public function getAuthIdentifierName()
327
-
{
328
-
return 'id';
329
-
}
321
+
protected $table = 'table_name';
330
322
331
323
/**
332
-
* Get the unique identifier for the user.
333
-
*
334
-
* @return mixed
324
+
* The Primary (Partition) Key.
325
+
* @var string
335
326
*/
336
-
public function getAuthIdentifier()
337
-
{
338
-
return $this->params['id'];
339
-
}
327
+
protected $primaryKey = 'id';
340
328
341
329
/**
342
-
* Get the password for the user.
343
-
*
344
-
* @return string
330
+
* The Sort Key.
331
+
* @var string|null
345
332
*/
346
-
public function getAuthPassword()
347
-
{
348
-
return $this->params['password'];
349
-
}
333
+
protected $sortKey = 'type';
350
334
351
335
/**
352
-
* Get the token value for the "remember me" session.
353
-
*
354
-
* @return string
336
+
* The default value of the Sort Key.
337
+
* @var string|null
355
338
*/
356
-
public function getRememberToken()
357
-
{
358
-
return $this->params['remember_token'] ?? null;
359
-
}
339
+
protected $sortKeyDefault = 'profile';
360
340
361
341
/**
362
-
* Set the token value for the "remember me" session.
`$response['Item']` will be the User model instance.
364
+
365
+
> behind the scene when specifying `usingModel`, Query Processor is converting each items to model instance with `(new $modelClass)-newFromBuilder($item)`.
366
+
367
+
After retrieving the model instance, we can `save`, `update` and `delete` in the same manner as Eloquent Model.
We can create Custom User Provider to authenticate with DynamoDB. For the detail, please refer to [Laravel's official document](https://laravel.com/docs/6.x/authentication#adding-custom-user-providers).
413
385
414
-
/**
415
-
* Retrieve a user by their unique identifier and "remember me" token.
0 commit comments