Press "Enter" to skip to content

Having a separate meta table made my day easier – Laravel

Sharing is caring!

WordPress has post_metas table that stores meta values of posts. This approach is very useful in laravel too. Rather than having to add columns using migration, inserting a new row seems much easier.

First, we will be creating meta table. Following is the schema to create the table.

The above trait is just to be used when ever a model needs to have the meta information.

Here is how to use it.

You can find the above code in github gists too.

Everything is awesome.

Comments are closed.