A few weeks ago I was searching Google for exactly the two words in the title, how to connect a Laravel 5 web application to a FileMaker database and I couldn’t find anything at all. Not really surprising, since that is one of the last things you would want to do.

So, why we wanted to do that in the first place? Well, we have a client that has a legacy application running on FileMaker and maintaining it was becoming a huge burden, so they want to migrate to something else. The server itself to host FileMaker is expensive (let alone it has to be a Mac or Windows) and it’s almost impossible to add new features.

While a Laravel connector for FileMaker was not found, I did find a PHP library to connect to FileMaker called SimpleFM. Adding a provider for it in Laravel was pretty easy (I also included the .env configuration introduced in Laravel 5 and the database.php configuration).

There is a bunch of ways you could have implemented this, I just wanted an easy way to get a FileMaker connection.

I also wanted to see information about the available layouts, since I prefer to avoid logging in to FileMaker at all costs. So I wrote a command to display all layout names in a database or to display column information in a specific database:

Please note: I’m using a Laravel 5.1 feature to describe the command as a signature, instead of the obscure and error-prone getOptions and getArguments.

Use it like this:

./artisan fm:show
Getting layout names
• Layout1
• Layout2
...

And you get a pretty table in response of a specific layout:

./artisan fm:show REPORTS
Getting info for REPORTS
+-------+-------+-------+
| index | recid | modid |
+-------+-------+-------+
| 0 | 77 | 0 |
+-------+-------+-------+

Take a look at the FileMaker docs for more commands and then you’re ready to do whatever you want with FileMaker inside your Laravel 5 application.

Happy hacking!

Advertisements