Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now
Build the future of communications.
Start building for free

PHP posts

  • By Chimezie Enyinnaya
    Laravel SanctumでPHPのRESTful APIを構築する Laravel SanctumでPHPのRESTful APIを構築する

    この記事はソフトウェアエンジニアのChimezie Enyinnayaこちらで公開した記事(英語)を日本語化したものです。

    Laravel Sanctum(旧称Airlock)は、シングルページアプリケーション(SPA)、モバイルアプリケーションや基本的なトークンベースのAPI用に作成されたLaravelパッケージです。これによりAPIトークンをユーザーに発行し、Laravelセッションを使用したシングルページアプリケーション認証が行えます。Laravel Sanctumは、既存のLaravel Passportパッケージの簡易版です。PassportよりもSanctumを選ぶ理由は以下のとおりです。

    1. PassportはOAuth2認証が実装されています。これを使用しないのであれば、APIトークンの発行はSanctumで行えます。
    2. Sanctumは超軽量でシンプルに実装できます。
    3. Sanctumは、Vue、Angular、Reactなどのシングルページアプリケーションに対応しています。モバイルアプリケーション認証も対応しています。



    1. Laravelの知識。
    2. Insomniaなど、HTTPクライアントの使用に関する基本知識。

    Laravel Sanctumでは多くのことができますが、このチュートリアルではLaravel Sanctumを使用したAPIの構築方法を説明します。



    Read More
  • By Oluyemi Olususi
    PHPUnitでLaravelのAPIをユニットテストする PHPUnitでLaravelのAPIをユニットテストする

    この記事はOluyemi Olususiこちらで公開した記事(英語)を日本語化したものです。



    このチュートリアルでは、テスト駆動開発の手法に従い、Laravel APIプロジェクトのエンドポイントをテストする方法について説明します。まず、失敗する前提のテストを記述します。その後、テストに合格するコードを記述します。チュートリアルを最後まで進めると、基本的なテストの実施方法について学び、新規または既存のLaravel APIプロジェクトに応用できるようになります。


    このチュートリアルを進めるにあたり、Laravelを使用したアプリケーション構築の基礎 …

    Read More
  • By Matthew Setter
    Working with Environment Variables in PHP Working with Environment Variables in PHP

    Environment variables are an excellent way to configure PHP applications because they keep the application’s settings outside of the code. By doing this, it's easier to prevent secure credentials from being exposed, maintain applications, and use applications across multiple environments.

    In this tutorial, you're going to learn about some of the many ways in which environment variables can be set and retrieved in PHP applications. That way, your application can access all the information that it needs, such as API keys, uploaded files, query strings, and form data.

    How to access environment variables in PHP

    Use PHP's Superglobals

    One of the most common ways that environment variables are accessed in PHP is through the use of Superglobals. These are built-in, predefined variables, available in all scopes. Initialised by the PHP runtime, they organise PHP's environment information in a (mostly) logical and efficient way, so that you only need to …

    Read More
  • By Oluyemi Olususi
    Build a Single Page Application in PHP with Yii 2.0 and Vue.js Build a Single Page Application in PHP with Yii 2.0 and Vue.js

    In the early days of the web, a series of static HTML files would be linked together to form a website. Clicking on page links would trigger requests to the server which would respond with a new HTML file.

    The rise of JavaScript and the advent of AJAX, however, made it possible to send and receive data from the server without full page reloads. These technologies added dynamism to websites, opening the door for a massive advancement in how websites operate today. For example, by using JavaScript, it is possible to handle user interaction and update websites via asynchronous requests.

    These types of websites became known as Single Page Applications (SPA). On the back of this, several JavaScript libraries and frameworks have risen to prominence - none more so than Vue.js.

    In this article, you will learn how to build a Single Page Application using Vue.js and the Yii …

    Read More
  • By Oluyemi Olususi
    How to Use the Repository Pattern in a Laravel Application How to Use the Repository Pattern in a Laravel Application Header

    A repository can be defined as a layer of abstraction between the domain and data mapping layers, one that provides an avenue of mediation between both, via a collection-like interface for accessing domain objects.

    Modern PHP frameworks, such as Laravel and Symfony, interact with databases via Object-relational mappers (ORMs); Symfony uses Doctrine as its default ORM and Laravel uses Eloquent.

    Both take different approaches in how database interaction works. With Eloquent, Models are generated for each database table, forming the basis of interaction. Doctrine, however, uses the Repository pattern where each Entity has a corresponding repository containing helper functions to interact with the database. While Laravel doesn't provide this functionality out of the box, it is possible to use the Repository pattern in Laravel projects.

    A key benefit of the Repository pattern is that it allows us to use the Principle of Dependency Inversion (or code to …

    Read More
  • By Matthew Setter
    How to Create a QR Code in PHP How to Create a QR Code in PHP

    QR codes are almost everywhere these days!

    It makes sense. They're small, readable on any modern smartphone without special software, and let us do so many things easily and quickly, such as checking in at a cafe, gaining access to a WiFi network, accessing a scooter on a summer vacation, and making a purchase.

    Here are some examples that I found from around the web.

    Some examples of QR codes.

    So if you want to know how to create them in your PHP-based application, read on.


    To follow this tutorial, you need the following:

    • Previous experience with writing PHP code.
    • PHP 7.4 with the GD extension installed.
    • Composer installed globally.
    • A smartphone.

    Let's create a QR code in PHP

    First, we need to create a project directory structure to store all the files that we'll make use of. To do so, switch into the top-level directory, and run the commands below.

    mkdir -p php-qr-code-generator …
    Read More
  • By Oluyemi Olususi
    Create One-Time Passwords in PHP with Symfony and Twilio's Verify API Create One-Time Passwords in PHP with Symfony and Twilio's Verify API

    As security threats continue to grow and their impacts become ever-more significant, Two-factor Authentication (2FA) is progressively becoming a de facto security standard. As an extra layer of security to the traditional username/email and password combination normally provided by the user(s) of an application, Two-factor authentication works and can be implemented by:

    • Generating and sending a numeric code to the user's mobile device either via SMS, email, or phone call. This is popularly called One-Time Password (OTP) as it is a short-live password that can only be used once during authentication.
    • Using an authenticator app to provide a constantly rotating set of codes that can be used for authentication when needed.
    • Using push authentication where a user responds to a device push notification to either approve or reject an in-application event.

    In this article, I will show you how to generate an OTP and send it to the user via …

    Read More
  • By Michael Okoko
    Laravel 7におけるCORS(Cross-Origin Resource Sharing)リクエストの処理 Laravel 7におけるCORS(Cross-Origin Resource Sharing)リクエストの処理

    この記事はMichael Okokoこちらで公開した記事(英語)を日本語化したものです。

    ウェブブラウザはデフォルトで同一オリジンポリシーを実装しており、スクリプトが異なるドメイン間でHTTPリクエストを行うことを防ぎます。 Cross-Origin Resource Sharing(CORS)は、自オリジンとは異なるオリジンからのリクエストを許可するか、または制限するかについて、ブラウザとサーバーサイドアプリケーション間で同意形成を行うためのメカニズムを提供します。


    このチュートリアルでは、Laravelを使用したシンプルなVue.jsアプリを作成し、CORSについて学びます。CORS OPTIONSリクエストを処理するためにLaravelが必要とする様々な設定オプションを深く掘り下げ、これらのオプションがアプリケーションにどのような影響を与えるかをご紹介します。



    • Laravelフレームワークに精通していること。
    • Laravelフレームワークのバージョンが7.0以上のプロジェクトが手元にあること。
    • Vue CLIがインストール済であること。


    Laravel APIとVueプロジェクトの両方を格納する新しいフォルダを作成し、Laravelプロジェクトを作成します。以下のコマンドを実行してください …

    Read More
  • By Joseph Udonsak
    A Beginner's Guide to Test Driven Development With Symfony and Codeception A Beginner's Guide to Test Driven Development With Symfony and Codeception

    Have you ever been afraid of your own code? Afraid to review it? Afraid to present it to clients or management? Afraid to explain it because, unwittingly, you have created a digital Jekyll and Hyde?

    That used to be me once upon a time until I took testing more seriously.

    Let's be honest, testing doesn't quite have the allure of writing production code, and it isn't as glamorous as writing complex data structures and algorithms. Are you excited to write a test case for code that you “know” works?

    While this doesn't make testing any less important, it has resulted in testing often being seen as an afterthought by so many; including managers, other developers-even me!

    In addition, testing didn't help me allay my fears because, somehow, all the nasty bugs were never exposed by my test cases. Okay, it didn't help that I never went back and updated …

    Read More
  • By Oluyemi Olususi
    Build a Bulk SMS Sender With Twilio, PHP, and Yii2 Build a Bulk SMS Sending Application With Twilio, PHP, and Yii2

    Notifications are an essential feature of an application because they provide an outlet for them to keep the customers updated with activities relating to their accounts. SMS notifications, specifically, provide a large reach due to the sheer number of phones in circulation. They also have the added advantage of accessibility because even customers using feature phones are able to receive notifications.

    Consequently, the question then becomes: how do you send SMS notifications to a large number of phones efficiently? This is because sending SMS notifications sequentially will likely create a scalability bottleneck.

    So in this article, I will show you how to send SMS notifications in bulk using Twilio, which makes managing/dispatching programmable SMS a breeze, and PHP's Yii2 framework. We will build an application that will send customized SMS notifications in bulk to clients via Twilio's SMS API.

    Tutorial Requirements

    To follow this tutorial, you need …

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