Francesco is a web developer and consultant from Italy. He is the founder of Laravel-Italia, the official Italian Laravel Community, and writes for HTML.IT, the first italian web development portal. He also translated some books about Laravel. In the meantime he follows other projects, works as a freelance backend consultant for PHP applications and studies IT Engineering in Rome. He loves to learn new things, not only about PHP or development but everything. He hopes to work for IBM, sooner or later.

Francesco's articles

  1. Bitcoin and PHP with Coinbase’s API – Demo App

    This entry is part 2 of 2 in the series Bitcoin and PHP with Coinbase's API

    In part 1, we covered basic installation and usage of Coinbase’s Bitcoin PHP API and the accompanying SDK. In this second and final part, we’ll be building our sample application.

    Send and Receive Bitcoins

    Sending or receiving BTC with the Coinbase API is really simple. There are a couple of intuitive methods you can easily guess: sendMoney() and requestMoney().

    Here’s the first one:

    public function sendMoney($to, $amount, $notes=null, $userFee=null, $amountCurrency=null)
    

    The first parameter is “who” will receive the money. The second one is the amount that you want to send. Transaction notes will be available only to recipients that also have a Coinbase account. Otherwise, the BTC network doesn’t support it.

    Let’s take a look at an example:

    $response = $coinbase->sendMoney($receiverAddress, "2");
    

    If you want to verify your transaction status, use the $response->transaction->status property.

    echo $response->transaction->status;
    

    You can also verify the result:

    if($response->success)
    {
        echo 'Done.';
    }
    

    If you want to get the transaction id, just use $response->transaction->id.

    Now let’s take a look at how you can request BTC. The method you will have to use is requestMoney() and this is its syntax.

    $response = $coinbase->requestMoney($emailAddress, 10, "Maintenance Operation (10 BTC)");
    
  2. Bitcoin and PHP with Coinbase’s API – Basic Usage

    This entry is part 1 of 2 in the series Bitcoin and PHP with Coinbase's API

    Have you ever thought about selling your services in exchange for Bitcoins? It’s not so strange – today, many big players are actually doing it. From OkCupid to KhanAcademy, even Wordpress is accepting Bitcoin. Also, some countries are thinking about it as a currency. Today, we will see how to accept Bitcoin payments on your website/application in an easy way, with the Coinbase API (and its SDK).

    Coinbase SDK

    Coinbase has some interesting tools and SDKs available for everyone, with some pricing conditions that are convenient and affordable.

    Here’s what you have to know about pricing:

    • Receiving payments with Coinbase is free;
    • You will have to pay a fee (1%) only if you want to transfer money on your bank account, but only if your sales exceed $1000000 (yes, one milion dollars);
    • The smallest payment you can do in the Bitcoin network is 0.001 BTC. Using a Coinbase wallet, however, that limit goes down to 1 Satoshi (0.00000001 BTC);

    Another important (and interesting) thing is that you can choose to activate the “Instant Exchange” service, which converts a Bitcoin payment amount immediately into a currency of your choice without additional steps, automatically. Really cool if you want to avoid the currency instability and transfer your money as soon as you can.

  3. Ardent: Laravel Models on Steroids

    One of the (few) things I don’t like about Laravel is that you cannot move the validation code from your controller to your models easily. When I write software I like to apply the “fat models, skinny controllers” principle. So, for me, writing the validation code in the controller is not a good thing.

    To solve this, I’d like to introduce Ardent, a great package for Laravel 4. To be more precise, Ardent presents itself as “Self-validating smart models for Laravel Framework 4’s Eloquent ORM.” In other words: exactly what we need!

    As you can imagine, it’s an extension of the Eloquent Model class, basically. This package comes with some new functionality, utilities and methods dedicated to input validation and other little things.

    Our Test Application

    For a better understanding of the advantages you can enjoy while using Ardent, we will set up a little test application. Nothing complicated: a simple To-Do List app.

    Of course, I’m not going to implement a complete application: I just want to explain some principles, so I will make some controllers and models – no views. After that, I will “translate” the code using Ardent.

    Our To-Do List will count two different entities:

    • User

      • id
      • first_name
      • last_name
      • email
      • password
    • Task

      • id
      • name
      • status (done / not done)

    A really basic project. However, if you don’t want to write code, don’t worry: I have already prepared a migration that you can use to generate the database. Use it!

  4. Fast PHP Routing with PHRoute

    PHRoute is an interesting package: it’s a fast regular expression based router that you can easily implement in small to medium projects. However, it’s not just very fast: there are filters, filter groups and named routes. You can also use a basic controllers system if things are getting bigger.

    That said, today we will see how to use it and how to implement its features in a sample project. Also, we are going to see what’s under the hood: PHRoute is a result of many experiments and tests by different people.

    Let’s start by installing it!

    Install

    You can add PHRoute to your project with Composer in seconds. Just add this line to your composer.json file:

    [code]
    {
    "require":
    {
    "phroute/phroute": "1.*"
    }
    }
    [/code]

    Type the composer install command and you’re in. Now, let’s move on to our test project.

    Sample Project and First Example

    For a better understanding of every concept of PHRoute, it is a good idea to have a sample project to work with. Today we are going to make a basic API for a books database service.

    Here’s the database scheme we are going to use:

    The Database Scheme

    If you want to do some tests, this is the SQL schema dump I used (with some extra dummy data).

  5. Getting Started with FluentPDO

    You know the story: writing SQL queries is so boring. Especially when you don’t have time to do it. If you feel like me, today we are going to see something really cool: Fluent PDO. If the term “PDO” sounds new to you, don’t worry. It’s a really simple concept: in the PHP world PDO stands for Persistent Data Object and it helps you abstract some basic database-related operations (like inserts, updates, deletes etc.). It’s a layer between you and the database.

    The result? No more SQL queries. Maybe this is not the first one you have seen: there are many similar projects out there and every single one has its key features. Fluent’s key feature is a great JOIN Query Builder.

    Our Test Project

    First of all, we will need a sample project to work with. Let’s think… what about a simple multi-user wishlist?

    There are going to be many users, and each will have favorite products. For every user we will store the first name, last name and the signup date. For every item we will store the name, brand, price and the related user id.

    I am going to use a simple MySQL database. Here’s the structure for our data:

    Sample Project Schema

    … and here’s the SQL dump (with some dummy data).