Fix Malformed UTF-8 characters, possibly incorrectly encoded error on Eloquent

This is one of those errors that are pretty much undocumented and can lead to a huge waste of time trying to figure it out why, so I’m going to tell you how I fix it and hope that helps you too.

I was trying to add binary data into the database using the save() method on the Model and it keep failing time after time saying:

InvalidArgumentException: Malformed UTF-8 characters, possibly incorrectly encoded in ../vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php

To fix this on Laravel you just need to make sure that you are inserting correctly the information, after a while I realize that I was inserting some truncated data on the table and the exception thrown by Eloquent was catched by the exception handler, and it contained some binary data that was being responded afterwards.

So this is just an error generated because the system was trying to report another previous error, now after the stress it’s gone, it’s kind of funny.


Use shared folder to develop with a VirtualBox Ubuntu Server guest

Recently the company that I work for change my Lenovo T440 with Ubuntu 16.04 for a MacBook Air with macOS and although I never really liked Mac (Too expensive for the specs provided) I loved the change but there are several differences that, when it comes to web development, I need to take in account, so I just installed a local Ubuntu 16.04 server with VirtualBox to test my work before to put it out.

To avoid having to pull the source code each time I just wanted to share the development folder with the guest machine and in order to do that we need to make the following steps

Install the VirtualBox Guest Additions in the guest

Continue reading

Change auto increment starting number on SQLite

For SQLite there is a table named SQLITE_SEQUENCE with all the auto incremental values of the tables, so you need to update the value.

UPDATE SQLITE_SEQUENCE SET seq = [starting_number] WHERE name = '[table_name]';

Just change [starting_number] for the desired initial auto increment and [table_name] for the name of the table to update