Binding an interface to an implementation promotes good coding practices. As a result the code is less coupled, more maintainable, and testable.

Why might someone want to bind and interface using Laravel? To put an abstraction between the application and the concretion. A concretion is a class that implements the interface. It is a specific implementation, in our example it will be Amazon S3 file storage provider. The application doesn’t care which implementation it receives just that it receives an implementation with the guaranteed functions.

Lets build functionality to interact with files on a storage provider such as Amazon S3. Initially all files will be uploaded and deleted on S3 only. There are other ways to accomplish this and the main goal is to demonstrate how to bind an interface to an implementation and not so much the actual code to upload to a storage provider.

Create An Interface

The interface will determine which functions are available on the concrete implementation through the binding.

Create The Concrete Implementation

The concretion is an Amazon S3 file storage provider. This file is where Amazon specific upload/delete functionality goes.

Create The Laravel Service Provider

The Laravel service provider is the mechanism that binds the FilterStorageInterface to the S3FileStorage class implementation. This means if we use dependency injection for the FileStorageInterface or use App:make it will automatically resolve to the S3FileStorage class.

Using The Interface

In the below example we are not using the implementation directly. Instead it is automatically resolved through the service provider which returns the concrete implementation. Laravel will automatically resolve dependencies if they are in the __construct() functions. We can see below that the controller doesn’t know about Amazon and nor should it. I am only using the controller in this example to provide a demonstration. There are other places where we would use the storage provider that might better organize the code.

Final Thoughts

If we wanted to swap out for Dropbox or some other provider the impact is minimal, create a Dropbox implementation and change the provider. The application would now use the Dropbox implementation instead of the Amazon S3 implementation.

Following this pattern can also help separate the application from Laravel which could make reusing this code in other projects easier than if the Amazon S3 code were included in a model directly. Definitely think about how to best structure your code and not to fall into the framework convenience trap of putting everything in a model, controller or view. In most cases there are better places for code than those 3 areas.

I had an issue where a social plugin will detect when people have commented or liked things on Facebook or Twitter and import those interactions into the blog post as comments.

The plugin imports the interactions as regular WordPress comments and unfortunately Disqus does not automatically 2 way sync WordPress comments and Disqus comments.

Fortunately a solution is available to automate the export of WordPress comments into Disqus comments using a cronjob. Run the below command in a cronjob and it will export the comments.

php -q <wordpressdir>/wp-content/plugins/disqus-comment-system/scripts/export-comments.php

Note: If your blog has a large amount of comments this process can potentially use a lot of system resources. Choose the frequency of running the command wisely so that it doesn’t impact users.


Source: WordPress Forums





  3. Click the check for upgrades button.
  6. Upgrade is finished.
  7. Check the site is up and running properly.

Post Upgrade



The idea is “x” framework provides a level of convenience that can make developers sloppy.

This often happens because frameworks tend to make developing easier. So easy we forget to take a step back and figure out how all the pieces come together.

If the framework is modeled on the model view controller (MVC) pattern. The convenience trap for developers is adding unnecessary amounts of logic into controllers or models. It’s easy to do and get the work “done” and out of the way if no testing is involved. Generally the problem with putting unnecessary amounts of logic in controllers or models is hard to test which subsequently causes the application to be brittle.

For example:
Oh looky here something database related this needs to go in a model or hey this interacts with the user’s input this probably goes in the controller.

The framework should not be the application, but a portion that compliments the development.

Note: The above generally applies to larger apps and not small apps that may have a short lifecycle.

How to mitigate the framework convenience trap?

  1. Write tests for the application. If tests are written chances are the structure of the app is designed better.
  2. Learn software best practices.
  3. Don’t code in a silo. Talk to other developers.
  4. Realize no one has perfect code and let someone critique your code. DON’T TAKE IT PERSONAL.


Knowledge Is Power

Educate yourself. Knowledge is power.






Read blogs, books or what ever sparks your interest.

Hard Work

Put in the hard work upfront and receive the benefits later.

Positive Attitude







Programming is useful and important.

I like to compare programming to oil in that cars require oil to operate and business require programmers. If a business intends to compete most likely they have an IT team. Many times the competitive advantage for a company relies on technology. Most technology if not all requires software development.

Even if very basic programming interests you there are some awesome courses. Some courses are self-paced and some have deadlines.

Awesome list of courses



