I was thinking if I should use this Eloquent Enhancement that implements only Models as array and json and then should I rewrite only some relation classes as HasOne, HasOneOrMany and Relation to get it done? Is that something affordable that worth it? Is there any Laravel SME can address me? Thanks.
Authenticating with Eloquent and without Database (How to handle user roles and permissions?)
Hi there, I've extended the UserProvider and the AuthServiceProvider to create my own authentication service management. I created a new Generic User from a json I get but now my question is :
How can I implement the relations between the user roles and permissions objects?
I mean, the json I get is provided with all the relations between the objects, so for better understanding, it is something like this:
{ id: 1, user: "hushhush" ,{role: { id: 1, name: "admin", permission: {[id: 1, name : "read"], [id:2, name: "write"]}}}}
Now, how can I create the Eloquent models with all the relationships without even using the database table? Will Eloquent query by the way the database for instance? Is there a way to tell Laravel to use models without fetching the db? Maybe I do not have to extend the Model in my models classes (User, Role, Permission)? But how to handle relations between models without db relations?
Thanks in advance!
I got it!!! Create a new Guard provider for user, session and cookie management, a new User Provider for user, roles and permissions management, create the three models extending Eloquent. Now, the User provider must handle the json got from the authentication api SSO and create user, role and permission models. Then, you have to choose if persisting the three models into your database or persist them only into the sessions. To persist the models into the session just remember to pass the session.store also to the User provider to store session objects. Change the retrieveBy{Id}or{Credentials} to fit your needs. For retrieveById, I just return the User model persisted to the session. Relations stay the same and you will be able to fetch roles and permissions from the user model as usual with all the eloquent relationship already in place. Then, use your database only for the stuff related to your application without implementing user, password, roles and permissions table since they will be managed centrally by the SSO system. I've also implemented a TokenManager to guzzlefy the SSO endpoint and return the json to the userprovider. It worked for me! Hope it could help others struggling with same stuff.
Please or to participate in this conversation.