baopham / laravel-dynamodb

Eloquent syntax for DynamoDB
https://packagist.org/packages/baopham/dynamodb
MIT License
484 stars 128 forks source link

Laravel Auth and DB Relations #47

Closed abishekrsrikaanth closed 7 years ago

abishekrsrikaanth commented 7 years ago

Just started using this package. Could you advise on how to use this package with Laravel Authentication and Authorization.

Additionally, how do I use Laravel Relations and Eager Loading with this package?

baopham commented 7 years ago

Could you advise on how to use this package with Laravel Authentication and Authorization.

Could you be more specific? Do you have a User model class? Does it extend Authenticatable?

how do I use Laravel Relations and Eager Loading with this package?

DynamoDB isn't a relational DB but if you need relations, you'd need to roll your own. For example, for relationship between manager and employees:

// First get the employee
$employee = Employee::find(<id>);
// Now to get the manager object, instead of doing `$employee->manager`, you'd do:
$manager = Manager::find($employee->manager_id);
abishekrsrikaanth commented 7 years ago

Authentication My question was if I can use the existing Authentication classes as is with this package? I don't see out of the box migrations for user tables? Should I write my own? If I matched the structure on DynamoDb with what Laravel provides out of the box. Would it work as expected?

Relations and Eager Loading Would I still be able to use the with method to retrieve the manager? I have a bit of background with MongoDB which is also not a relational DB and this is something I have been able to do with https://github.com/jenssegers/laravel-mongodb#relations . So just trying to understand if the same would be possible with this package as well.

Migrations Do you plan to support Migrations in the near future? Currently, I have to use a https://github.com/quanvhframgia/laravel-dynamodb-migrations/ to be able to do this, but isn't that intuitive in comparison to Laravel's Migration syntax. It would be great if it is was supported as part of this package itself.

baopham commented 7 years ago

Hi @abishekrsrikaanth, sorry for not responding. I've been busy with other work.

My question was if I can use the existing Authentication classes as is with this package

Have you tried? :)

I don't see out of the box migrations for user tables?

Migrations are not supported here.

Should I write my own?

Why not?

If I matched the structure on DynamoDb with what Laravel provides out of the box. Would it work as expected?

Not all, you can see the README and tests to see what is supported.

Would I still be able to use the with method to retrieve the manager?

nope

Do you plan to support Migrations in the near future?

I'll check out the library you mentioned, we will see. It all depends if I have the time...

but isn't that intuitive in comparison to Laravel's Migration syntax.

It's hard to match it exactly with Laravel's migration syntax as DynamoDB has its own concepts so there is no 1 to 1 mapping between Laravel feature and DynamoDB feature.

baopham commented 7 years ago

I'll close this for now

kevinyea commented 6 years ago

Hello Bao, On the subject of Auth as per #47 My initial application used mysql and I'm in the process of migrating to DynamoDB. What is left is the Auth part (i.e. still have dependency on mysql for that reason and just those tables). Can you give some advice on how to approach and implement DynamoDB-based Auth functions using your dynamodb incarnation of eloquent please. Many thanks Kevin

zoul0813 commented 6 years ago

@kevinyea, my project was originally setup with DynamoDB Auth using laravels basic Auth setup. I’ve since migrated to Cognito for Auth though.

I don’t recall running into any issues using DynamoDB for Auth, although you may want to consider costs and a proper caching layer (memcache/redis) as you’ll be reading from the user table with every request that is logged in.

ebbbang commented 6 years ago

Hey @baopham , My User Model is extending Authenticatable. How am I to use DynamoDBModel with the User Model. As I also need Authenicatable for using the Auth::login($user) method.

ebbbang commented 6 years ago

Hey @baopham, I found out how to use your package with Laravel Auth.

  1. Extend User Model with BaoPham\DynamoDb\DynamoDbModel.
  2. Implement Illuminate\Contracts\Auth\Authenticatable interface in User Model.
  3. Include \Illuminate\Auth\Authenticatable Trait inside User Model.

E.g.

<?php

namespace App;

use BaoPham\DynamoDb\DynamoDbModel;
use Illuminate\Contracts\Auth\Authenticatable;

class User extends DynamoDbModel implements Authenticatable
{
    use \Illuminate\Auth\Authenticatable;
}

Voila, Now I can use User Model in Laravel Auth while also using BaoPham\DynamoDb.

Please ask me if anyone wants more details.

baopham commented 6 years ago

Awesome! Thanks for the follow up. I haven't had the time to check.