Laravel: creating a column with a specific encoding

In order to persist preformatted messages for social media postings, I needed to be able to save emoji's to a new column in my MySQL database. It turned out that my basic utf8 character encoding was not up to the task.

A quick fix appeared to be changing the encoding of my database to utf8mb4. The steps involved seemed simple enough, but I was put off but talk of converting and possibly repairing data After all, eventually I would have to apply the change to the production database. 

I realized that all I really needed was a different encoding for a single column. Luckily, Laravel supplies this option. I requires two changes.

In my database migration, I needed to specify a charset for the newly created column:


This worked like a charm. I could save emoji's directly to the new column now. Processing the data in my front end was still an issue though. My database configuration required an  update. In my definition of mysql variables, I updated these two lines:

'charset'   => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci'

After this update, loading and saving emoji's worked without issues.