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.
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. …
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?
The steps to create that are:
This is what jsonapi.org says about delete(we will be covering when the resource is not exist, and another state when the field exists and delete success)
From those specs above, there are few tests that we need to do:
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.
What We will be checking
So let’s write those tests first
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. …
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:
This route will show one item from database. When you make a new function on your codebase, you would think…
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.
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…
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.
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…
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).
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…