Sending Emails Using Push Queues With Confide

Using push queues to send emails offers significant benefits to your application. It boosts application performance which in turn improves the user experience which in one way or another generally leads to a more successful application.

Confide, being built specifically for Laravel 4, has its own mail method that handles translation among other things. This mail method is used for common user account emails such as account confirmation, password resets, etc. With that in mind, to use push queues with with Confide you will need to override the sendEmail() method.

To override the Confide sendEmail() method open up User.php that you created (or edited) when installing Confide and add the following code.

After saving this file, your application will now use a push queue to send user account emails.

Securing Laravel Push Queues

Push queues are the all the hype at the moment. However, I have not seen much discussion around securing them. Thats likely do the the simplicity of securing the receiving route, but either way…lets cover it.

There are two basic ways to secure the receiving route.

  • SSL – Use a security certificate to secure the connection.
  • Token and Route Filter – Build a route filter that requires a valid token.

Route Filter & Route Example

Configure the subscriber URL on to look something like the following. In this example the URL query string is set to the value of the token in app/config/queue.php.

Role Specific Drop Downs in SugarCRM

Today I ran in to a scenario where I needed the status field for projects to hide a value for everyone except two specific roles. I did some googling and found a post which seemed to theoretically accomplish what I was looking for. However, in practice it didn’t. That said, I won’t be covering what didn’t work as nobody really cares.

Now down to business. The first thing we need to do is edit the vardefs of the drop down to use a custom function that will handle the logic of determining if the specified value is available for selection.

Next, create the file and function to handle the logic.

Finally, run Quick Repair and Rebuild. The drop down is now hiding the “Pending Input” option for everyone except users in the Developer and Marketing roles.

A Small But Troubling Trend With Laravel Packages

Edit: I have updated the “Correct Service Provider” with code provided by William Cahill-Manley in his comments. Thanks for the contribution William!

Watching Laravel 4 grow has been spectacular. Its great to see so many libraries building service providers and facades for Laravel to make them feel more native to the framework. That said, I have noticed small but troubling trend with some packages available for Laravel.

The Problem

The problem lies in how configuration is handled for the package. Configuration should not be done within the service provider. This concept is not unique to Laravel. However, for this post I will be discussing Laravel packages specifically. Below is simple example of one such package.

At a glance, this file doesn’t appear to require configuration. If you look deeper (or refer to the documentation) you will find the developer can change the geocoding provider and adapter used for geocoding services. The ability to pick which geocoding provider and adapter to use is tremendous in allowing developers to build applications to do exactly what they want. The problem lies in the implementation of such configuration.

As you can see above, to use a different geocoding provider and/or adapter the developer must adjust the service provider to instantiate an alternate geocoding provider and/or adapter. Let’s say the package receives an update and the developer pulls down that update via composer. What happens to the “configuration”? It gets wiped out. Now the application is broken and the developer must update the service provider again. Wash. Rinse. Repeat.

The Solution

To solve this issue the package should (and now does) implement a publishable configuration file. The configuration file allows the developer to specify which geocoding provider and adapter to use for geocoding services.

So what do the new service provider and configuration look like? Take a look.

return array(
    'provider' => 'Geocoder\Provider\FreeGeoIpProvider',
    'adapter' => 'Geocoder\HttpAdapter\CurlHttpAdapter'

 * This file is part of the GeocoderLaravel library.
 * (c) Antoine Corcy <>
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.

namespace Toin0u\Geocoder;

use Geocoder\Geocoder;
use Illuminate\Support\ServiceProvider;

 * Geocoder service provider
 * @author Antoine Corcy <>
class GeocoderServiceProvider extends ServiceProvider
     * Indicates if loading of the provider is deferred.
     * @var bool
    protected $defer = false;

     * Bootstrap the application events.
     * @return void
    public function boot()

     * Register the service provider.
     * @return void
    public function register()

    public function registerAdapter() {
        $this->app->singleton( 'geocoder.adapter',
            $this->app['config']->get('geocoder-laravel::adapter', 'Geocoder\HttpAdapter\CurlHttpAdapter')
    public function registerProvider() {
         $this->app->singleton( 'geocoder.provider',
            $this->app['config']->get('geocoder-laravel::provider', 'Geocoder\Provider\FreeGeoIpProvider')
    public function registerGeocoder() {
        $this->app['geocoder'] = $this->app->share(function($app) {
            $geocoder = new Geocoder;

            return $geocoder;

     * Get the services provided by the provider.
     * @return array
    public function provides()
        return array('geocoder', 'geocoder.adapter', 'geocoder.provider');

Now you may ask, “How do you configure this package?”

Simple. Run the following command after installing the package via composer.

$ php artisan config:publish toin0u/geocoder-laravel

After the configuration has been published the developer can edit it to use the geocoding provider and adapter of their choice. The published configuration file will allow the developer to update via composer without worrying about breaking their application (from a configuration stand point at least).


Configurable packages are a great thing. That said, let’s wear our “best practice hats” and make sure we keep the configuration out of Composers reach.

Using SugarCRM’s New RESTful API With Guzzle

Today I saw a post from Mr. John Mertic that described how to interact with the new API via cURL. While it’s a great piece of information, I find working with the Guzzle library to be much more efficient due to Guzzle’s support for event listeners. That and I hate working directly with cURL.

That said, lets get down to business and start working with the new API.

First, lets update composer.json to install Guzzle

    "require": {
        "guzzle/guzzle": "~3.1.1"

Next, install the library via composer

$ composer install

Now with Guzzle auto loaded we can start to have our fun with the new API.

use Guzzle\Common\Event;
use Guzzle\Http\Client;

// specify the REST web service to interact with
$url = 'http://sugarinstance/rest/v10';

// And admin username/password
$username = 'username';
$password = 'password';

$client = new Client($url);

//Authenticate and retrieve an OAuth2 Token
$request = $client->post('oauth2/token', null, array(
  'grant_type' => 'password',
  'client_id' => 'sugar',
  'username' => $username,
  'password' => $password,

$results = $request->send()->json();

$token = $results['access_token'];

//Register an Event Listener to automatically include 
//the OAuth2 token on all requests to the REST web service
  'request.before_send', function(Event $event) {
    $event['request']->setHeader('OAuth-Token', $token);

//Retrieve all documents related to the specified account
$request = $client->get('/Accounts/' . $account_id . '/link/documents');
$result = $request->send()->json();


As you can see, using Guzzle makes interacting with the new API a breeze and has an added bonus of making the code much easier to understand.

Stay tuned, on my next post I’ll show how you can use the SugarCRM 7 API Wrapper Class to accomplish the same task in just a few lines of code.