&
Love building with Twilio? Want to win $1500? Join our online hackathon Apr 2-30, 2020.
&
Build the future of communications.
Start building for free

"php" posts

  • By Gary Hockin
    My 3 Favourite Things From Laravel 7 My 3 Favourite Laravel 7 Features

    Laravel 7 has released. And like any proper major release, it's packed to the rafters with new and exciting features. It's time to take a look at three of my favourite new features, and, if we're lucky, there might be a bonus feature at the end.

    You’ll need some existing knowledge of PHP and a little Laravel knowledge to follow along. You can find the sample code used in this article on GitHub.

    Custom Casting with Eloquent

    Eloquent, Laravel's object relationship mapper is a useful tool for moving data between our database and our code. We could do some sensible type conversions using Eloquent’s Mutators already. For example, add any field to the $dates property of our model and it is automatically converted into a Carbon date object for us.

    Custom Casts take this a step further by helping us to decouple how our data looks in …

    Read More
  • By Dotun Jolaoso
    How to build a Laravel Twilio Package for SMS How to Build a Laravel Twilio Package

    I recently realized that every time I had to do an integration with Twilio for sending SMS in a Laravel project, I used a custom wrapper around the Twilio PHP library to help me simplify the process. However, this became a bit monotonous for me as I always had to copy and paste this wrapper every time I was starting a new Laravel project. In this tutorial, you’ll join me in learning how to build a Laravel Twilio Package to eliminate copying and pasting and benefit from package management. This will also allow other developers such as yourself to make use of this package.

    Technical Requirements

    To complete this tutorial, you will need the following:

    Setting up a New Package

    We’ll be using Composer to set up the package. From the terminal, cd into your project’s directory and run the following command:

    $ composer init
    

    This …

    Read More
  • By Gary Hockin
    PHP 7.4 - 6 Compelling New Features Graded PHP 7.4 - 6 Compelling Features Graded

    PHP 7.4 has arrived, and it's shipped the usual raft of exciting features and improvements. For a recent live stream, we looked at all the features in the release notes and figured out what each one means in a coding sense. Let's take a look at some of the new features in PHP 7.4, and grade each one from A-F depending on how interesting they are, and my excitement to use them.

    Note: This is my personal opinion based on my own unique experiences and opinions. You'll probably disagree with some of my grades, and that's good. Your opinions and experiences are different from mine. Let me know in the comments or on Twitter where you feel I went wrong.

    Typed Properties

    We've been waiting for this feature since PHP 7.0 introduced scalar type declarations and return types, and I, for one, am very excited. We can now set …

    Read More
  • By Gary Hockin
    Adding Twig as a View Renderer to Slim in PHP Adding Twig as a View Renderer to Slim in PHP

    Slim is an excellent PHP micro-framework. Out of the box it gives you compatibility with PHP standards (PSRs), PSR-11 for the container, PSR-7 for HTTP messages and PSR-15 for middleware. Its lightweight design gives you the bare minimum to get started with your web application; routing, a middleware dispatcher, error handling and a container. You need to wire up the additional services needed to handle requests and return responses.

    But where do we start? Let's take a look at installing a clean installation of Slim from a community skeleton, and add our first component to it; the Twig templating engine.

    Starting with Slim

    Slim provides a skeleton application that lets you get started quickly, but it's designed more with an API in mind than a web application. I prefer to start with a more lightweight skeleton from Slim maintainer Rob Allen. Rob’s starter comes with PHP-DI dependency …

    Read More
  • By Paul Kamp
    Install the Twilio PHP Helper Library Without Composer php-helper-library-no-composer-header

    PHP is a venerable language. As I go to press, it’s in major version 7 and has maintained it’s well-deserved popularity for nearly 25 years.

    With two and a half decades of evolution, we PHP developers have quite a few ways to do things. To wit: many of you ask us how to use Twilio’s PHP Helper Library directly, without a package manager.

    Today, I’ll show you how to install Twilio’s PHP Helper Library on *NIX or Mac OSX without using the package manager Composer.

    Let’s compose some magic.

    Prerequisites to Install The Twilio PHP Helper Library (Without Composer)

    Before we get started with the install, you’ll need to set a few things up, confirm a few others, and find a phone:

    Read More
  • By Gary Hockin
    Static Analysis with Psalm PHP Copy of Generic Blog Header 4-10.png

    PHP is great, but its loosely-typed goodness is a double-edged sword. On the one hand, it gives PHP the legendary low barrier to entry, but on the other, magical type juggling inevitably means bugs.

    Because PHP is an interpreted rather than compiled language, catching these type problems is tricky, and often they'll go unnoticed for a long time before they catch up with us somewhere down the road. Problems sit and fester in our code base waiting to strike. Unused code can clutter our application, and there is a myriad of other ways in which we write PHP that won't produce errors but are bugs.

    There are some excellent tools to help us catch errors and find bugs before we even run our code. IDEs like PhpStorm can inspect our code and give us information on potential problems before a script is ever executed.

    Screenshot of PhpStorm IDE showing an inspection finding an unused variable

    Catching problems with our code before …

    Read More
  • By Gary Hockin
    What’s New in Laravel 6: Ignition and Flare Copy of Photo blog Header 1(1).png

    Laravel 6.0 is released, and as a new major version, there are plenty of fun new features for us to play with. The release notes give us all the highlights, but as part of a recent stream, I decided to take a look at one of the more exciting additions, the new error handler, Ignition.

    Ignition

    Ignition replaces Whoops as the default error handler in Laravel 6, but it works on older Laravel applications going back to version 5.5. The impressive thing about Ignition is because it's designed from the ground up to handle Laravel's specific errors, it can make suggestions on how to resolve errors, and even automatically fix common problems for us.

    If we deliberately add a typo in our blade template name, then Ignition realises this and suggests the fix for us in the green panel.

    Screenshot of Ignition detecting a typo of "homex" and suggesting that we meant to type "home"

    Even smarter is the fact that Ignition can automatically …

    Read More
  • By Gary Hockin
    Responding to SMS in PHP using AWS Lambda and Bref lirlC01lUZ-27G-NyFFBrv34hXhjGT9x8FzpwBi8g0eSizEMwtdkfOICi6wok5aYS6eR3Crdg3zO7cJ3hq-iF9Da4etsyTNy48qK_qffrAsklPtWGe3WRpb3u3CiPP9C8WzWTomD

    Every new starter at Twilio has to build an application using one of our products, then demo it to receive their fabled Track Jacket. For my application, because WiFi is always a pain at conferences, I wrote a PHP script that sends you the next talks for a given event.

    Writing this so it worked locally was relatively straightforward with PHP’s inbuilt web server and ngrok, but when I got up to demo this in front of my peers, I didn’t want to be relying on my laptop to be open, awake and responding to the proxied HTTP requests. This code needs to be sitting somewhere on the internet so that it can respond to messages any time of the day or night, and not just when my laptop was open and connected to the wifi.

    Serverless functions are great for this; they allow you to run code on …

    Read More
  • By Margaret Staples
    Encoding Diversity: A New Sponsorship Tool Logos from Employee Resource Groups celebrating and supporting diversity at Twilio.

    A little over a year ago my team lead looked at my first few months as a Developer Evangelist and decided that since I was already doing work for and with underrepresented developers, that we should try making that one of the communities I officially serve.

    All through 2018 I ended up having the same conversations about inclusion, representation, and accessibility with event organizers again and again. Everything from venue accessibility, to Codes of Conduct issues, to representation - every organizer was starting from square one on at least some of the concerns most important to underrepresented developer communities.

    Looking at the perpetual churn of community volunteers putting together events I realized this was an inevitable ongoing issue and needed an ongoing solution that could scale in a way my one on one conversations could not.

    One of my favorite things to do with code is facilitate emotional labor, so …

    Read More
  • By Margaret Staples
    PHP + Twilio + Whatsapp: Would You Like to Play a Game? PHP Twilio WhatsApp

    There are 1.5 billion people using WhatsApp's end to end encrypted messaging platform to communicate. Many of those people prefer WhatsApp to SMS and other messaging platforms. It's currently the most popular messaging app in the world.

    Twilio is adding options to the same API calls you use to send and receive SMS messages with Twilio, so you can now reach those users the way they prefer: on WhatsApp.

    Using the Twilio API Sandbox for WhatsApp in your Twilio console, you can experiment with this new channel for connecting your software to the world.

    Here are a few ways you can play with the Twilio API Sandbox for WhatsApp using PHP.

    Before Getting Started

    To code along with this post, you'll want:

    Read More
  • Newer
    Older
    Sign up and start building
    Not ready yet? Talk to an expert.