Why differs the sample implementation of a driver from the laravel lock?
burzum opened this issue · 2 comments
The Laravel lock uses a single table, see this file. But the example implementation in the readme.md shows two tables. Why? And why would I use the two tables instead of the single table from the Laravel plugin?
I'm asking because I'm building a CakePHP 3.0 plugin which has been so far surprisingly easy because the ORM is almost the same as Laravals. I copied the Laravel driver and started adapting the code and I think I'm already done with the very basics (test aside). My only show stopper right now is if I should or have to use one or two tables for a better implementation.
Edit: After reading the code a little more I guess the two table solutions would be better because I can see that the driver interface features Role and Caller methods? So I assume the methods that have Role in their name should use the roles table and the other methods the callers table? Is that how it is thought?
Well, it's totally up to you tbh. For the example, I took Eloquent and used two separate models. Each Eloquent model is mapped to a separate table. That's why I used two separate tables in the example. For the Laravel driver I'm using Laravel's DB component and thus I wasn't bound to use separate tables.
Come to think of it, now that you mention this, I could have just used a Permission
model for that particularly example. I'm probably going to update that example so it'll be more easily to digest. Thanks for making me aware of that.
The main reason why I use a single table is because besides the specific identifier columns the rest of the schema is practically the same. I also don't want to pollute a user's database with all sorts of different permission tables. One table is enough. I could have added some indexes on the identifier columns though, I might add that at some point.
Thanks for that answer Dries! Yes, I think the example could explain the reason for that or simply reduce it to a single table. It doesn't matter if you just copy and paste it but as soon as you start thinking about why something is done as it is it causes open questions, at least it did for me.