Watch this tutorial on my YouTube channel!
Why not use ‘var’? This may be the question that you might be asking when you see the title of this article. That’s right! The
var keyword might be one of the most painful features of the language. Over the years, with the introduction of the
const keywords in ES6, people have been in love with the
const keywords ever since. Let’s take a look at the whys.
Before we continue, let’s take a brief look at what is actually a scope.
In general, a scope can be…
You’ve got a lot of files and nested files in a directory. However loading them 1 by 1 using
require is simply too painful. Life is already tough, so please don’t do that to yourself.
In this tutorial, I will show you a few ways to achieve this.
PHP is kind enough to offer us the iterator classes to work with iterables. However, the APIs are quite low level. Let’s take a look at the code:
An iterator is an object to loop through a series of items. You can think of iterator as the OOP way of looping.
Laravel provides a nice and convenient API for us to define our app routes. There are 2 ways to define a route group: the array syntax via
group() or the method syntax. Personally I love the array syntax by calling the
group() method provided by the
Route facade. However using it is not as straightforward as one may think, and primary reason for that is because it is undocumented at the time of writing this article.
Route group essentially helps us to group multiple routes together under the same middleware, prefix, name or namespace. This is especially convenient when we…
So you spent quite some time crafting your awesome React App 🎊, and it is time to publish it and share the love with everyone else. Github Pages is a free static site hosting service that works quite well with most use cases. Let’s learn how we can deploy a React app for free in Github pages!
JSON is the de-factor choice of transmitting data across the internet in the modern day. Its easy-to-read nature is pleasing for both human and computer.
When we are sending API requests we usually use JSON formatted string as our request payload. However, it has its flaws when it comes to sending data, i.e. it can only send data that can be converted into string. Binary data like images, PDF files can’t be sent with JSON.
So how do we resolve this?
The answer is: use
Getting authentication right is not a straightforward task. Thankfully, Laravel has released an official authentication package called Laravel Fortify that took care of everything about authentication for us.
In summary, Fortify mainly consisted of 7 components:
Laravel Fortify has preloaded a lot of API endpoints for us. Below is a brief overview on the endpoints that are available to us.
Non XHR API:
On success, redirect to
home route defined in fortify…
There are quite a few casing systems out there. Camel case, snake case pascal case, kebab case and etc. Let’s explore their use case scenarios!
Developers love to use conventions! They help us to organise our code and improve maintainability.
When it comes to naming variables and data structure in our code we use casing conventions to differentiate variable types and symbols.
The followings are the common usage for each casing convention.
camelCase is for variables, function names, arguments and other generic uses.
snake_case is similar to
camelCase but we usually choose either one and stick to it for the…
Setting request query parameter can be very useful, especially in testing. We can set the request query parameter on runtime using the
$request->merge() function. Here’s how:
/** @var $request \Illuminate\Http\Request */
$request = app()['request'];
'page' => '3'
]);dump($request->page); // expect: '3'
In Testing Classes, we should access the app instance via
// TestClass extending TestCase/** @var $request \Illuminate\Http\Request */
$request = $this->app['request'];
'page' => '3'
merge function will modify the current request in-place. If you want to clone the request, you can use the
$request = app()['request'];// cloning the request so we don't modify the source
$newRequest = \Illuminate\Support\Facades\Request::createFrom($request);$nreRequest->merge([
'body' => 'heyy']);dump($request->body); // expect null
That’s it! Happy coding.
API (Application Programming Interface) sounds complicated, but it just means “function”!
When we are interacting with a computer, we don’t need to care about the inner working of a computer, i.e.
All we care about is how to use a keyboard and a mouse. In other words, keyboard and mouse are the interfaces for us human to use the computer. This applies to other objects as well. …
Sometimes we just want to run composer command directly in our PHP code. But there seems to be no other easy solution other than
shell_exec() … or is there?
It turns out there is a built-in
Composer helper class in Laravel’s ecosystem! Yes, that’s right, it lives under the
Illuminate\Support namespace. However, it doesn’t have a method to run arbitrary composer commands out of the box.
Let’s tweak it and add some new flavour! 😎
We will create a new Composer class that inherits
Programatically install a package:
If you see…