Beat API using Slim Framework and Eloquent ORM Laravel

Di-posting pada 2014-09-15 08:54:05
Oleh Sonny Lazuardi, Category : Web

After reading the following article slim-and-laravel-eloquent-orm, I see that the simplicity of these two tools can be combined. We can get the power of routing from slim framework and the power of active record model from eloquent orm (laravel), and this would be amazing. So before sterted, I want to show you the application API that I made from slim framework and eloquent ORM. You can access both applications on the following links

  • Snippet App Snippet app is the place where You can share and save Your notes or codes that will be saved in your custom url on Snippet app provide modern editor like sublime text that make you familiar with.
  • Beat App Beat app is a url shortener application that make you easier to remember your long url link.


In this post, I will only explain about the beat api for url shortener. So, here is my directory structure of SonnyLab API that uses slim framework and eloquent orm.

|_ models
    |_ Beat.php
|_ public
    |_ styles
    |_ images
    |_ scripts
    |_ beat.html
|_ vendor
    |_ composer
        |_ autoload_classmap.php
|_ index.php
|_ composer.json

So the first thing to do is writing composer.json :

    "name": "SonnyLab API",    
    "require": {
        "php": ">=5.3.0",
        "slim/slim": "2.*",
        "dhorrigan/capsule": "*"
    "autoload": {
        "classmap": [

Composer is a php package manager to auto load class php package automatically. We use package capsule to get rid of eloquent model orm outside the laravel. After writing the composer.json, we need to install it using the following command (using command prompt in your project directory)

> composer install

Wait the installation process. Next step is to set the configuration to connect to database mysql.

<form method="post">
   URL : <input type="text" name="url" placeholder="" value="<?php echo $beat->url ?>"> <br><input type="text" name="slug" placeholder="pendek" value="<?php echo $beat->slug ?>"> <br><br>
   <button class="btn">Simpan</button>
So, you have seen the magic of both tools slim framework and eloquent orm that make you develop web app simpler. I hope you are helped with this tiny tutorial of what I have done to reach the best practices in web development. Critics and suggestions are welcomed :D.