Photo by Aron Visuals on Unsplash

strtotime would give you full timestamp, and its not straightforward(for me) to find minute/hour/day (or any number of minute) difference. I propose using Carbon library because it is easier and this library has been proven and maintained.

The Problem

I have 2 commands that needs to run every 15 minutes alternating between 2 different date range parameter. I wrangled with strtotime for some time without any solution, then thought that this app(Laravel) has Carbon library. Surely they must have classes and features for comparison like this. So I read their documentation and found what I was looking for. …

Photo by Sigmund on Unsplash

Have you ever try to create an HTML page from a design and wonder how could I make a loop for this element (like ecommerce product listing) so I could write CSS for one element and make it apply on all of those list without copy and paste?

Using templating engine like blade, or thymeleaf, or jinja seems to be overkill for such a small project right?

Enter Alpine.js, it is a Javascript library for you to make a certain element loop and fill it with data from a Javascript object.

The steps to create that are:

  • add alpine.js to…

Photo by Gary Chan on Unsplash

This is what says about delete(we will be covering when the resource is not exist, and another state when the field exists and delete success)

  • if resource does not exists, returns 404 and empty body
  • if resource exists, delete and return 200 and empty body

The Test Cases

From those specs above, there are few tests that we need to do:

  • test when we request delete to non existent record, it will return 404
  • when we request delete to record that exists, it will delete it from database. But since we are using soft delete feature from Laravel, we still has the…

Photo by rithwick. pr on Unsplash

In many API guidelines, there are 2 ways to update a resource, one is sending only the attribute(s) that needs to be updated, for example you only want to update price, you only send key price with value the new price. The second one is forcing client to send all the attributes to update the resource. What differentiate those 2 ways of updating resource would be the HTTP verb that they use, which is PATCH and PUT (surprise! there are more HTTP verbs other than GET and POST). If we allow the clients to send only the updated attribute(s) we…

After we have create routes to show the items that we have, now it is time for us to make a URL for creating new item. As always, the steps that we will take to create this functionality is creating the test, then make the code.

The Test

What We will be checking

  1. name, description, sku, stock, and price is required
  2. check if the request that we make is saved to database
  3. the response has same values as the one we sent to the server

So let’s write those tests first

* creating…

Photo by Jakob Owens on Unsplash

Previously we have create a route to show one article using Resource class, in this one, we will reuse the Resource class to build our list of items. The route that we will build is like the index page in a CRUD function. In website settings, index page usually lists a kind same type of information, take an example of Instagram, if you open instagram home page, it will list posts of those you follow, or amazon, where it will list a number of items it sell, with pagination links below the item lists. …

Photo by timothy muza on Unsplash

Previously, we have tried how to create a route and process it inside the routes/web.php file. Now we will make a route, then handle it in a controller, as this is common way people do; the infamous MVC. Though we will not render a view but return JSON.

This is the step that we need to creating an index route:

  1. Create Route, link it to a controller function.
  2. Capture the request.
  3. Query data from database.
  4. Return a response to requester.

What This Route Do?

This route will show one item from database. When you make a new function on your codebase, you would think…

Photo by Llanydd Lloyd on Unsplash

Welcome back to part 3 of the Lumen API series. in this part we will define how to create and populate the database with fake data. Because we will create a test cases for each functions that we make, we should make sure that the database content is controlled to make sure the test is close to real data.

Activate Eloquent Capability

Model in Lumen is an ORM, it connect the tables and columns from database to make an easier way to access and manipulate database. Let’s activate the ORM support in lumen, it is disabled by default in lumen because Lumen seek…

Photo by Campaign Creators on Unsplash

TL;DR; Yes


  1. You could extend the app.
  2. You could refactor the app.
  3. You could experiment.
  4. Confidence doing that things above because you have the tests covers you. Something breaks, there’s high chance the test cases will tell you before the app going into production.

But I could do that too even if I do not test my application. Why bother testing?

Okay, let’s talk about some painful memories.

Faster Development

When we develop some feature, usually there are many type of input it could have, either desired on undesired input. From the specification, the developer would design the developed feature to…

Photo by Daniel Bradley on Unsplash

This is the second part of my post about creating Lumen API, in this part we will explore on how to create an endpoint, so other people could access our site to do something, and we could give response to their request. Even if they try to make some ridiculous request (spoiler alert, its mostly 422).

Route 101

Now that we have some introduction on Lumen’s directory structure on previous part, let’s see how we could create route. As we have read in previous post about folder structure, the routing definition in Lumen happens in routes/web.php , so lets open that file…

Yanuar Arifin

Software Engineer. Currently PHP. How far could we automate things?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store