Welcome Guest, Not a member yet? Register   Sign In
Integrating relationship query builder similar to Laravel
#1
Lightbulb 

So I hate to compare frameworks, but I love Laravel's relationship query builder. I actually integrated this into my CodeIgniter 4 installation and I would love to share it with others. So far, I did the more complex relationship (BelongsToMany). I have it setup almost exactly the same way as Laravel, but using CodeIgniter's Builder. However, I ran into one issue where I needed the QBSelect property to be public or have a getter method for this in the BaseBuilder so I just adjusted this inside the vendor directory which isn't the best thing to do, but I really didn't want to override all the Database, BaseConnection, Postgre (the driver I'm using) Connection, and all those other classes I would have to extend and create instances of inside the connect() Config/Database method. So for now, I made this small one liner change.
I am working on creating a repository for everything I have so far. I adjusted the way attributes are set on the model as well so they are now nested inside the attributes property which when casted to array or json, the __get and __set will use those attributes. I also added scopes into my query builder so now you can call a method directly on your model and it will check for a scopeMethodName() and pass the builder instance into the first parameter similar to what Laravel has.
If anybody is interested, I would love to share my code with you. I have everything inside my App\Models directory right now and am using my own BaseModel class that extends CodeIgniter's Model class. And it provides all this functionality on top of it.
What does everybody think about this?
I'm working on the other relationships right now Smile . But I have pivot columns and everything working for the BelongsToMany where you can specify what pivot columns you want if any!
Reply


Messages In This Thread
Integrating relationship query builder similar to Laravel - by hlohrenz - 07-25-2019, 08:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB