Author: Jarek (page 3 of 4)

Laravel Query Builder global scope – how to use custom Connection and Query Builder in Laravel 4


Eloquent Global Scopes make it easy to customize your Model’s queries, however sometimes it is just not enough.

You may want to use similar solution for you DB::table(..) calls as well. While there’s no built-in feature for this, you can still do it with just a little more effort, and here’s how it’s done.

Continue reading

sofa/revisionable – nice & easy way to keep track of db changes


It is essential for every application to keep track of the data revisions. As an admin or sort of supervising user, you want to know how, when and who is responsible for changing the data.

Here’s something you should try out, because it makes this kind of work stupid-simple:


Continue reading

Tweaking Eloquent relations – how to get hasMany relation count efficiently?


When working with relationships, most likely you need to get count of related models in many places. There are obvious ways to achieve this of course, but not always efficient. Especially when you are loading a collection of models and their relations.

So let me show you what we can do about it!

Continue reading

Laravel – how to define and use Eloquent Global Scopes

Laravel 4.2 introduced a new way of handling soft deletes by making use of traits and query builder macros wrapped in as a feature, that many people asked for for a very long time – Global Scopes.

This might be very useful for everyone, however the docs are not very eloquent in this case. So keep on reading to learn how you can implement global scopes in your project – it’s really easy and lets you write even more expressive code for your Eloquent models.

Check the ready-to-use demo at …

Continue reading

Tweaking Eloquent relations – how to get N related models per parent ?


Previously I showed you how to get single related model per each parent, while eager loading the hasMany relation. That was pretty easy and we just made the most of the Eloquent.

However, most likely the time will come, when you need several related models per parent.

It won’t be as easy, but it’s far from impossible, so let’s do it!

Continue reading

Tweaking Eloquent relations – how to get latest related model?


Have you ever needed to show only single related model from the hasMany relationship on a set of parents?

Being it latest, highest or just random, it’s not very clever to load whole collection using eager loading, just like running query per every parent.

Of course you can do that better, and now let me show you how.  Continue reading

How to store clients in database? That is, Party Model implemented in Laravel 4 – part 1


Have you ever been building any app that handled client’s data, was it e-commerce, crm or anything similar, you surely wondered, how to store it in the database.

Most of the time we consider client as Organization or Person, one or the other. Obviously the two are completely different entities in real life, so it wouldn’t be wise to treat them the same. However, speaking of business, we want to treat both entities like a client, no matter if it’s a company or an individual.

So the problem arises, how to design the database efficiently while not having to do checks here and there within our code, to pick what entity we are dealing with this time.

And here comes the Party Model  Continue reading

Querying relations in Laravel 4: nested relation


Previously we dealt with simple relations defined in Eloquent models and eager loading them in order to save database queries.

Now imagine nested relations like this:

So there are one-to-many relations between posts & categories as well as comments & posts.

Above relations look like this:

Continue reading

Querying relations with Eloquent in Laravel 4


Laravel ORM Eloquent is brilliant!

That being said, let’s try to tackle very common questions that appear when you try to get related models loaded.

Continue reading

New project open – RMA@SOFA

Starting new project called RMA@SOFA.

It will cover most of the needs of service points, starting with IT services, then much more!

Roadmap and features outline will be here soon. Also there will be case study for package development and a few tutorial-ish posts/screencasts.

Stay tuned!

Olderposts Newerposts

Copyright © 2020 SOFTonSOFA

Theme by Anders NorenUp ↑