Summary

Our Meta package is used for adding key/value attributes to Eloquent models. This approach is great for storing user-defined data that is not essential to your application, i.e. data such as multiple telephone numbers and addresses that you might find on a contact page.

How it works

So, here we have a concept of using Meta fields/attributes instead of model properties. Let’s look at the Users model. Typically we would have their name, email, password, but we also want to have height, gender, age, favourite colour, first pet, sports team etc.

Ordinarily, we could create columns in the database to store these model properties.  However, if we moved all these columns of extra data into a singular table we can then reference these properties via a new relationship ‘meta’, with a key identifier.

The benefits of this approach will give you a flexible data structure allowing you to extend models without having to create endless columns in the database.

Packagist: developerswarehouse/meta