Using AYLIEN Text Analysis API with Laravel 5

Using AYLIEN Text Analysis API with Laravel 5

One of our users, Michael Hopkins, recently built a Laravel 5 friendly wrapper, around our AYLIEN PHP SDK, which makes it really easy for the Laravel community to use our API.

Michael wanted to incorporate our API and provide the facade, “Aylien::” to a Laravel 5 app he was building. Thankfully for us and for Laravel users, he decided to the make this wrapper publicly available on GitHub. He’s even gone so far as designing a nice graphic to accompany his work. Nice job Michael!



If you haven’t heard of Laravel, you can read more about the PHP Framework here.

Michael put together a clear and concise guide to getting up and running with his wrapper, along with a neat little example app, that showcases the wrapper in action, which we’ll walk through in this blog.

What you’ll need to get going




You can add this package to your composer.json and update the composer by running/adding either of the below commands.

"hopkins/laravel-aylien-wrapper": "dev-master"


composer require hopkins/laravel-aylien-wrapper=dev-master

Once you’ve updated the composer, add the AYLIEN ServiceProvider to the providers array in app/config/app.php


You’ll also need to add the facade into your array of facades as shown below:

'Aylien'    => 'HopkinsLaravelAylienWrapperFacadesAylien',

Next, run the artisan tool to bring the config into your project with the following command:

php artisan vendor:publish

Don’t forget to add your AYLIEN API keys, if you haven’t got yours yet, you can sign up here. Michael went for the option of adding his AYLIEN credentials to the .env file.

To use this style of config you can copy the below into your config/aylien.php

return [
    'app_id' => env('API_AYLIEN_APP_ID'),
    'app_key' => env('API_AYLIEN_APP_KEY')

Example App

Michael Provides an example app he built that logs all messages from a chat/email client/ contact form in a DB using a public static function boot() method and then analyzes the text using the AYLIEN API. In the example below Michael analyzes the sentiment of the text.

class Message extends BaseModel
    protected $guarded = ['id'];
    public static function boot()
        Message::created(function(Message $message)
            $aylienResponse = Aylien::Sentiment(['text'=>$message->message]);
                'polarity' => $aylienResponse->polarity,
                'polarity_confidence' => $aylienResponse->polarity_confidence,
                'subjectivity' => $aylienResponse->subjectivity,
                'subjectivity_confidence' => $aylienResponse->subjectivity_confidence

The rest of the AYLIEN endpoints can be invoked using the following commands.


If you’ve built something cool with APIs and would loke to share it with the AYLIEN community, drop us a line at we’d love to hear from you.


Let's Talk