<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Imran Hossain (Rubab)</title>
    <description>The latest articles on DEV Community by Imran Hossain (Rubab) (@rubab2020).</description>
    <link>https://dev.to/rubab2020</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F68098%2F617e4096-af55-427f-9441-c6a741d8e2d4.jpg</url>
      <title>DEV Community: Imran Hossain (Rubab)</title>
      <link>https://dev.to/rubab2020</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rubab2020"/>
    <language>en</language>
    <item>
      <title>Docker for Beginners</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Wed, 01 May 2024 08:25:44 +0000</pubDate>
      <link>https://dev.to/rubab2020/docker-for-beginners-25oe</link>
      <guid>https://dev.to/rubab2020/docker-for-beginners-25oe</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Docker?&lt;/strong&gt;&lt;br&gt;
Docker is an open-source software platform that enables developers to run applications on any machine. This removes the pain of setting up and configuring different machines for running the same application. Docker allows you to create, deploy, and manage virtualized environments on a common operating system (OS).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Using Docker&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Same Environment Consistency: Docker ensures applications behave the same way on any machine (local and remote servers).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Continuous Integration and Delivery (CI/CD): Containers are ideal for CI/CD workflows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites for Learning Docker&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Basic understanding of Linux commands&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;File system concepts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User groups and permissions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How Docker Works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Docker runs containers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A container encapsulates all the code and environment needed to run an application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It includes the operating system, configuration, and application code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Difference Between Virtual Machines and Containers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frx964fmqiuz517301ut8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frx964fmqiuz517301ut8.png" alt="Image description" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Virtual Machine (VM):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A virtual machine gets its own full operating system, including a kernel (the core that controls low-level tasks).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This approach is resource-intensive on the host machine running the VMs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Architectural layers: Server, Host OS, Hypervisor, VMs (App, Bins/Libs, Kernel)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Container:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A container is not a full virtual machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It shares the host(our PC) machine’s kernel but maintains isolation through a unique file system (a feature of Linux distributions).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Docker uses this file system to create isolated environments.&lt;br&gt;
Containers start up quickly and use fewer resources (disk space, memory) compared to VMs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Architectural layers: Server, Host OS, Container (App, Bins/Libs, Kernel)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Image:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An image is a template for a running instance called a container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An image defines the OS, software, and application code, all bundled up in a single file called a Dockerfile.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rexdw8tkhkpj0r7517m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rexdw8tkhkpj0r7517m.png" alt="Image description" width="321" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dockerfile:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A Dockerfile is a text file containing instructions to create an image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can configure the operating system, install required software, copy project files, and more.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let’s Build Our First Image&lt;/strong&gt;&lt;br&gt;
We’ll create a PHP file that prints “Welcome to code with rubab” when a user visits our website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an index.php file:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php echo "Welcome to code with rubab"; ?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this file as index.php in your project folder named code-with-rubab&lt;/p&gt;

&lt;p&gt;Now we will create a file called “Dockerfile” inside our project folder to create an image. We will configure our environment to run our index.php file inside Dockerfile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Dockerfile:&lt;/strong&gt;&lt;br&gt;
Create a file named Dockerfile inside your project folder. This file will define how to build the image.&lt;/p&gt;

&lt;p&gt;First, we need an operating system with PHP and Apache installed. Apache is a web server software. In our traditional way, we had to install the OS, apache, and php manually. But with docker, we have images already built that save tons of time. Our image will be built on top of that Apache build. There are lots of existing images for Apache and we can find those images on &lt;a href="https://hub.docker.com/_/php"&gt;the Docker hub&lt;/a&gt;. Here, we will use a Debian OS-based PHP.&lt;/p&gt;

&lt;p&gt;code-with-rubab/Dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM php:8.2.0-apache
COPY . /var/www/html
EXPOSE 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;FROM php:8.2.0-apache: This line specifies the base image we'll use. It's a pre-built image containing PHP and Apache.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;COPY . /var/www/html: This copies all files from the current directory (.) to the /var/www/html directory within the container. This is where Apache looks for web application files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;EXPOSE 80: By default, the Docker container ignores all incoming requests. This line tells Docker that the container listens on port 80, the standard port for web traffic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: When you copy files into the container using the COPY instruction, Docker marks all subsequent build steps as “dirty” and re-runs them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Build Command:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyliglr4r5gl0vc189xum.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyliglr4r5gl0vc189xum.png" alt="Image description" width="321" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To build the image, navigate to the directory containing the Dockerfile in your terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t code-with-rubab .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;-t: This option specifies a tag for the image. Here, we're naming the image ascode-with-rubab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;.: The dot (.) refers to the current directory where the Dockerfile is located.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What Happens Behind the Command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first time we run this command, it downloads all the layers of the base php:8.2.0-apache image. Then, it copies our project files into the image and creates a new image named code-with-rubab.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But you will get an error when you run this command&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ERROR: error during connect: this error may indicate that the docker daemon is not running&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Solution: We need a docker engine. If you are a Windows user download from &lt;a href="https://docs.docker.com/desktop/install/windows-install/"&gt;here&lt;/a&gt;. For window users, we need to do some extra work to run this docker engine.&lt;/p&gt;

&lt;p&gt;When you run docker engine on Windows, you will see this alert message&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Docker desktop is unbale to detect a hypervisor&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To solve this issue we need to enable hypervisor. To do this, we need to enable Virtualization technology from BIOS settings, Install the Windows subsystem for Linux, and finally need to enable the hypervisor and Windows subsystem for Linux from Windows features on and off settings. &lt;a href="https://www.youtube.com/watch?v=qeaFtGtQvUw&amp;amp;list=PLLhwyo0tKUfv3DianBA7L_7VlyIWLYczw&amp;amp;index=17"&gt;Check the steps from here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now after installing and running the docker engine, we can build our project properly and a successful image build will look like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7hka75f7vsbw5fz4rtx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7hka75f7vsbw5fz4rtx.png" alt="Image description" width="415" height="141"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To check the new image we can simply type this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jg17ob2s3x62l6lkghi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jg17ob2s3x62l6lkghi.png" alt="Image description" width="576" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Run command:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fql0o53hfzp7ue86sisxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fql0o53hfzp7ue86sisxy.png" alt="Image description" width="521" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we will create a container from the image we have just created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -p 80:80 code-with-rubab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;-p 80:80: This option maps port 80 on the host machine (our computer) to port 80 within the container. When a request reaches our computer’s port 80, Docker forwards it to the container’s port 80. The container’s EXPOSE line in the Dockerfile allows it to accept this request, and Apache handles it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;code-with-rubab: This is the name of the image you want to run to create a container.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, if we hit a browser URL with localhost then we will see the “Welcome to code with rubab” message which means our application is running inside a Docker container, Yay!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fydlx518b2d0zzscusyqv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fydlx518b2d0zzscusyqv.png" alt="Image description" width="312" height="142"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus:&lt;/strong&gt;&lt;br&gt;
Now, If you try to change the message from the codebase and set a new welcome message “Welcome to Rubab, Rashed, and Rasel’s planet” then you will see the message is not reflected in the browser.&lt;/p&gt;

&lt;p&gt;What happened?&lt;/p&gt;

&lt;p&gt;The docker does not know what has been changed in our codebase as the code was already shipped with the docker image and until we rebuild and re-run our container we will not get the reflection of changes. This a very tedious work and we do these boring tasks.&lt;/p&gt;

&lt;p&gt;To make docker look for changes we make in our codebase, we need to add volume in our docker run command. So, if we build our image now, docker will know where to check changes on our machine during the container’s run time. So, we will add volume now.&lt;/p&gt;

&lt;p&gt;First, we to stop the running container with Ctrl+c.&lt;/p&gt;

&lt;p&gt;Now, add the volume to our docker run command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Docker  run -p 80:80 -v &amp;lt;path-of-your-project-directory&amp;gt;/:/var/www/html/ code-with-rubab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-v = v means volume&lt;/li&gt;
&lt;li&gt;/:/var/www/html = / is our host’s project directory, in my case my local PC directory was “D:/docker/docker-beginner/” and “/var/www/html” is our container’s directory path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, the changes we make now will be reflected in the browser.&lt;br&gt;
One more thing, After running the docker run command we are unable to interact with our current shell. So, to do this we will run the container in the background or detached mode. For this, we will use -d for detached mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Docker  run -d -p 80:80 -v &amp;lt;path-of-your-project-directory&amp;gt;/:/var/www/html/ code-with-rubab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we will be able to use the current sell. Let’s see our running container by typing this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps // ps is short form of process which is a container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j87h501j0r0sq2uk2ny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j87h501j0r0sq2uk2ny.png" alt="Image description" width="720" height="102"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Docker Commands:&lt;/strong&gt;&lt;br&gt;
I’ve listed down more commands to play with our current docker setup. There are lots of other docker commands we can google on the browser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build --no-cache -t &amp;lt;image-name&amp;gt;. // force a complete rebuild
docker build --progress=plain -t &amp;lt;image-name&amp;gt; . // detailed build info

docker image prune // clean dangline images
docker image rm &amp;lt;image-name&amp;gt;

docker ps -a // all running/stopped
docker stop container-id // stop a container
docker container prune // clean stopped container

// To interact with container using sh (shell command). 
// Example:we can check our index.php file in the container
docker exec -it container-id sh 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Notes on Container:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The container’s lifetime is directly tied to its main process, one process per container. If the main process terminates, even if background tasks are running, the container will stop automatically without warning.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Containers are lightweight, allowing you to run many containers simultaneously on a single machine.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But we need to run a complete project using MySQL, Laravel, redis, and phpmyadmin. What about if I have frontend react app and backend Laravel API projects? Don’t worry, this is just the first part of my Docker series. In my next Docker article, I will cover the whole process (Hint: Docker Compose).&lt;/p&gt;

&lt;p&gt;Happy Learning!&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>webdev</category>
      <category>devops</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Securing Sensitive Data with Encryption Algorithms</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Sun, 28 Jan 2024 04:21:17 +0000</pubDate>
      <link>https://dev.to/rubab2020/securing-sensitive-data-with-encryption-algorithms-3mc</link>
      <guid>https://dev.to/rubab2020/securing-sensitive-data-with-encryption-algorithms-3mc</guid>
      <description>&lt;p&gt;Encryption is the process of converting plain text into an unreadable form(ciphertext) to protect from unauthorized access.&lt;/p&gt;

&lt;p&gt;There are 2 types of Encryptions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Symmetric-Key encryption&lt;/li&gt;
&lt;li&gt;Asymmetric encryption (public-key encryption)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How encryption algorithms work:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encryption:&lt;/strong&gt;&lt;br&gt;
Plain text is input into the algorithm.&lt;br&gt;
The algorithm uses a key to perform a series of complex mathematical operations on the plain text. The output is ciphertext, which is unreadable without the key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decryption:&lt;/strong&gt;&lt;br&gt;
Ciphertext is input into the algorithm.&lt;br&gt;
The algorithm uses the correct key to reverse the mathematical operations.The output is the original plain text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Symmetric-Key encryption:&lt;/strong&gt;&lt;br&gt;
It uses the same key for both encryption and decryption. It is fast and efficient for large amounts of data. Secure keys are exchanged between parties.&lt;/p&gt;

&lt;p&gt;There are two main types: block ciphers and stream ciphers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Ciphers:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Block ciphers encrypt data in fixed-size blocks (e.g., 64 or 128 bits) using a key.&lt;/li&gt;
&lt;li&gt;A widely used block cipher is the Advanced Encryption Standard (AES), which supports key lengths of 128, 192, or 256 bits.&lt;/li&gt;
&lt;li&gt;The data is divided into blocks, and each block is encrypted independently.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Stream Ciphers:&lt;/strong&gt;&lt;br&gt;
Stream ciphers encrypt data bit by bit or byte by byte, typically in a continuous stream.&lt;br&gt;
One common stream cipher is the Rivest Cipher (RC4).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: AES (Advanced Encryption Standard)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function encrypt($data="", $key="") {
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length("aes-256-cbc")); // dynamic iv (we can also set static iv)
    $encrypted = openssl_encrypt($data, "aes-256-cbc", $key, 0, $iv);
    return base64_encode($iv . '!!' . $encrypted);
}
function decrypt( $data="", $key="") {
    list($iv, $encryptedData) = explode('!!', base64_decode($data), 2);
    return openssl_decrypt($encryptedData, "aes-256-cbc", $key, 0, $iv);
}

$plainData = [
    'email' =&amp;gt; 'codewithrubab@gmail.com',
    'password' =&amp;gt; 'codeOn@Vscode2024';
];
$saltKey = "asdckd44dbc228e16c2888436d17a";

$encryptedData = encrypt(json_encode($plainData), $saltKey);
echo $encryptedData;
$decryptedData = decrypt($encryptedData, $saltKey);
print_r($decryptedData);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If we need to re-generate same encrypted data on same plain text then we need to always use same Salt Key and IV. Otherwise, the output will be different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asymmetric encryption (public-key encryption):&lt;/strong&gt;&lt;br&gt;
It uses two different keys: a public key for encryption and a private key for decryption.&lt;/p&gt;

&lt;p&gt;we don’t need secure key exchange for encryption. It’s slower than symmetric encryption and useful for digital signatures and authentication,&lt;/p&gt;

&lt;p&gt;Common public-key encryption techniques: RSA, ECC (Elliptic Curve Cryptography), Diffie-Hellman.&lt;/p&gt;

&lt;p&gt;Let’s see an Example with RSA Algorithm.&lt;/p&gt;

&lt;p&gt;If we don’t have the public and private keys then we can generate from the command line interface.&lt;/p&gt;

&lt;p&gt;For private key file generation in a directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;openssl genrsa -out privateKey.pem 2048&lt;/code&gt;&lt;br&gt;
For public key:&lt;br&gt;
&lt;code&gt;openssl rsa -in privateKey.pem -pubout&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, privateKey.pem and privateKey.pem are the generated file names.&lt;/p&gt;

&lt;p&gt;The generated public key is a RSA result.&lt;/p&gt;

&lt;p&gt;The private Key is not a RSA result. To make it a RSA result we need to write some code.&lt;/p&gt;

&lt;p&gt;First, install this package in your Laravel Project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Composer require "phpseclib/phpseclib": "~2.0"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use phpseclib\Crypt\RSA;


// private key: pem to rsa code
$privateKey = 'set pem file data';
$rsa = new RSA();
$rsa-&amp;gt;loadKey($privateKey);
$rsaPrivateKey = $rsa-&amp;gt;getPrivateKey();
dd($rsaPrivateKey);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, if we need to convert a public key from pem to RSA then we can convert using this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// for public key: pem to rsa.
$publicKey = 'set pem file data';
$rsa = new RSA();
$rsa-&amp;gt;loadKey($publicKey);
$rsa-&amp;gt;setPublicKey($publicKey);
$rsaPublicKey = $rsa-&amp;gt;getPublicKey();
dd($rsaPublicKey);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Let’s see a real life implementation of Asymmetric Encryption:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s assume we are making a transaction with a bank as a merchant. Bank provided us a public key and we have shared our public key to the bank. From our end, we will encrypt our transaction request data using our private key and send it to the bank. Bank will decrypt the data using our provided public key. Bank then process the data and send us an encrypted response using their private key. After receiving the bank’s response we will decrypt using their public key to get the plain response.&lt;/p&gt;

&lt;p&gt;In addition to that, Bank has asked us to send a signature with every transaction request. They also told us that we need to decrypt the decoded Sensitive Data using Merchant Private Key with PKCS1Padding Algorithm. The signature will be generated using SHA256withRSA signature algorithm.&lt;/p&gt;

&lt;p&gt;Now, We will make an api call to initiate a transaction to the bank’s end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public  function signatureGenerate($data){
   $private_key = "-----YOUR RSA PRIVATE KEY-----";
   openssl_sign(json_encode($data), $signature, $private_key, OPENSSL_ALGO_SHA256);
   return base64_encode($signature);
}   


public function encryptDataWithPublicKey($data){
   $public_key = "-----YOUR PUBLIC KEY-----";
   openssl_public_encrypt(json_encode($data), $encryptedData, $public_key, OPENSSL_PKCS1_PADDING);
   return base64_encode($encryptedData);
}


public function decryptDataWithPrivateKey($cryptText){
   $private_key = "-----YOUR RSA PRIVATE KEY-----";
   openssl_private_decrypt(base64_decode($cryptText), $plainText, $private_key, OPENSSL_PKCS1_PADDING);
   return json_decode($plainText, true);
}


public function HttpPostMethod($postURL, $postData, $authToken = null)
{
   try {
       $curl = curl_init($postURL);
       $postData = json_encode($postData);
       $header = array(
           'Content-Type:application/json'
       );

       if($authToken){
           $header[] = 'token:' . $authToken;
       }


       curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
       curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
       curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);


       $resultdata = curl_exec($curl);


       $err = curl_error($curl);
       $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
       $curlErrorNo = curl_errno($curl);


       $ResultArray = json_decode($resultdata, true);
       curl_close($curl);
       return $ResultArray;
   } catch (\Exception $exception) {
       echo 'Failed to Connect with Bank. Please try again later';
       exit;
   }


}


initTransaction($merchantId, $merchantAccountNumber, $orderId){
   $postUrl = 'api.your-bank.com/api/payment/initialize';
   $plainData = array(
       'merchant_id' =&amp;gt; $merchantId,
       'order_id' =&amp;gt; $orderId
   );
   $postData = array(
       'account_number' =&amp;gt; $merchantAccountNumber,
       'sensitiveData' =&amp;gt; $this-&amp;gt;encryptDataWithPublicKey($sensitiveData),
       'signature' =&amp;gt; $this-&amp;gt;signatureGenerate($sensitiveData)
   );


   return $this-&amp;gt;HttpPostMethod($postUrl, $postData);
}
$encryptedResponse = $this-&amp;gt;initTransaction('MER1234', 'ACC12345', 'ORD123456');
$plainResponse = $this-&amp;gt;decryptDataWithPrivateKey($encryptedResponse['sensitiveData']);
dd($plainResponse);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bonus:&lt;br&gt;
Here is a useful link to &lt;a href="https://8gwifi.org/RSAFunctionality?rsasignverifyfunctions=rsasignverifyfunctions&amp;amp;keysize=2048"&gt;RSA Signature/Generation &amp;amp; Validation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Things to consider when choosing an Encryption Algorithm:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Level of security required.&lt;/li&gt;
&lt;li&gt;Speed of encryption/decryption.&lt;/li&gt;
&lt;li&gt;Key management complexity.&lt;/li&gt;
&lt;li&gt;Resource constraints.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Where encryption algorithms are used&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Secure communication (e.g., emails, VPNs)&lt;/li&gt;
&lt;li&gt;Data storage (e.g., databases, file systems)&lt;/li&gt;
&lt;li&gt;Financial transactions (e.g., online banking)&lt;/li&gt;
&lt;li&gt;Password protection&lt;/li&gt;
&lt;li&gt;Digital signatures&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>encryption</category>
      <category>php</category>
      <category>laravel</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Efficiently Managing Data with SELECT During INSERT Queries</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Tue, 26 Dec 2023 15:54:44 +0000</pubDate>
      <link>https://dev.to/rubab2020/efficiently-managing-data-with-select-during-insert-queries-4l63</link>
      <guid>https://dev.to/rubab2020/efficiently-managing-data-with-select-during-insert-queries-4l63</guid>
      <description>&lt;p&gt;We may sometimes need data which is already present in table but we need that data during insert. If we query data first and then insert the data, it will require running 2 SQL commands. But it will be best to run just one single SQL command that will query the data first and set the data during INSERT Query.&lt;/p&gt;

&lt;p&gt;This technique elegantly merges data retrieval and insertion, streamlining the process and reducing the number of queries required.&lt;/p&gt;

&lt;p&gt;Let's see an Example:&lt;/p&gt;

&lt;p&gt;Consider a website's menu structure stored within a table named menus. Each menu item holds properties such as:&lt;/p&gt;

&lt;p&gt;id: A unique identifier&lt;br&gt;
menu_name: The name of the menu item&lt;br&gt;
parent_id: The identifier of the parent menu item (if applicable)&lt;/p&gt;

&lt;p&gt;To establish a parent-child relationship between menus, we can effectively leverage a SELECT during INSERT query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO `menus` (`id`, `menu_name`, `parent_id`)
(SELECT
   NULL,
   'childMenu',
   menu.id &amp;lt;--- setting the parent menu id
FROM `menus` AS menu
WHERE menu.menu_name = 'parentMenu'
LIMIT 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Breaking Down the Query:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;INSERT INTO menus (id, menu_name, parent_id): This segment initiates an INSERT operation into the menus table, targeting the specified columns.&lt;/li&gt;
&lt;li&gt;SELECT NULL, 'childMenu', menu.id: This represents a nested SELECT query that retrieves the desired data for insertion.&lt;/li&gt;
&lt;li&gt;FROM menus AS menu: The source table for the SELECT.&lt;/li&gt;
&lt;li&gt;WHERE menu.menu_name = 'parentMenu': This condition filters the results to locate the specific parent menu item.
5.LIMIT 1: This constraint ensures that only a single row is selected, preventing potential duplication issues.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Optimized Performance: Combining operations into a single query often enhances execution speed.&lt;/li&gt;
&lt;li&gt;Enhanced Readability: Nesting queries can improve code organization and clarity.&lt;/li&gt;
&lt;li&gt;Data Integrity: This approach safeguards data consistency by ensuring parent-child relationships are accurately established during insertion.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>mysql</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Virtual Host Setup with SSL Certificate in Your Localhost</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Mon, 04 Dec 2023 04:34:21 +0000</pubDate>
      <link>https://dev.to/rubab2020/virtual-host-setup-with-ssl-certificate-in-your-localhost-4mca</link>
      <guid>https://dev.to/rubab2020/virtual-host-setup-with-ssl-certificate-in-your-localhost-4mca</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqmzwmm9h343y2y8vltl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqmzwmm9h343y2y8vltl.png" alt="Image description" width="677" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article we will learn how we can run our project from a custom url example.com instead of localhost in our local LAMP Server on Ubuntu.&lt;/p&gt;

&lt;p&gt;First open your terminal and create a New file called example.com.conf with root privileges.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;touch /etc/apache2/sites-available/example.com.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open the new file with root privileges.&lt;br&gt;
&lt;code&gt;sudo nano /etc/apache2/sites-available/example.com.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add below lines in the example.com.conf file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
  ServerName example.com
        DocumentRoot /var/www/html/example-project
  Redirect permanent / https://example.com
&amp;lt;/VirtualHost&amp;gt;
&amp;lt;VirtualHost *:443&amp;gt;
  ServerAdmin example@example.com
        DocumentRoot /var/www/html/example-project
  ServerName example.com

  SSLEngine on
  SSLCertificateFile /var/www/html/ssl/server.crt
  SSLCertificateKeyFile /var/www/html/ssl/server.key
  SSLCertificateChainFile /var/www/html/ssl/rootCA.pem

  &amp;lt;Directory "/var/www/html/example-project"&amp;gt;
    Options Indexes FollowSymLinks
    AllowOverride All
        Require all granted
  &amp;lt;/Directory&amp;gt;

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we have added http with port 80 and https with port 443. We have also added redirection to example.com to &lt;a href="https://example.com"&gt;https://example.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For SSL certificate, Please create a ssl certificate and then add the crt, key and pem type files in a ssl folder under /var/www/html folder. Please note that we have mentioned path for the crt, key and pem files for VirtualHost port 443 above. Finally, we enabled htaccess by “AllowOverride All”.&lt;/p&gt;

&lt;p&gt;Now save the file and it’s time to add our custom host to the host file.&lt;/p&gt;

&lt;p&gt;Open the host file in terminal by the command&lt;br&gt;
&lt;code&gt;sudo nano /etc/hosts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add our example.com to the end of file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1   localhost
.....
.....
127.0.1.1   example.com // add this line
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To enable SSL and new vhost config file use these commands&lt;br&gt;
&lt;code&gt;sudo a2enmod ssl // to enable ssl&lt;br&gt;
sudo a2ensite example.com.conf // to enable vhost config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now restart the server to apply the changes&lt;br&gt;
&lt;code&gt;sudo systemctl restart apache2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Test it now by visiting example.com&lt;/p&gt;

&lt;p&gt;If we face any problem then we will be able to see in /var/log/apache2/error.log file.&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>apache</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Create a Multi Language Based Website With Laravel</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Thu, 19 Oct 2023 03:46:37 +0000</pubDate>
      <link>https://dev.to/rubab2020/create-a-multi-language-based-website-with-laravel-5ib</link>
      <guid>https://dev.to/rubab2020/create-a-multi-language-based-website-with-laravel-5ib</guid>
      <description>&lt;p&gt;This article goes in detailed on how to make a website multilingual in Laravel. Users will be able to set the language English or Bangla and the whole site will be translated accordingly.&lt;/p&gt;

&lt;p&gt;First, create a Middleware called SetLocale. To create the middleware, open your terminal and run below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:middleware SetLocale
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will create SetLocale.php file inside Middleware Folder. We will use session to store user’s selected language. Now in the handle funtion add below code so that the middleware can check the session data to set the website language when a web route uses the middleware.&lt;/p&gt;

&lt;p&gt;app/Http/Middleware/SetLocale.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class SetLocale
{
    public function handle(Request $request, Closure $next)
    {
        if(is_null(session('locale')))
            session(['locale'=&amp;gt; 'en']); // set language english if language is not set in session

        app()-&amp;gt;setLocale(session('locale')); // set the session's language to our application

        return $next($request); // this will already be available in the handle request. It just passes the request to next handle.
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we need to register our middleware in the Kernel.&lt;/p&gt;

&lt;p&gt;app/Http/Kernel.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $middlewareGroups = [
    'web' =&amp;gt; [
        \App\Http\Middleware\SetLocale::class
    ]
];

protected $routeMiddleware = [
    'setLocale' =&amp;gt; \App\Http\Middleware\SetLocale::class
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will apply our middlware inside our web routes. Also we will create a change language route where selected route will be set to the session.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;routes/web.php
--------------
// middlware applied on base route
Route::group(['middleware' =&amp;gt; ['setLocale']], function () {
    Route::get('/', function () {
        return view('welcome');
    });
});

// language change option route
Route::get('/change-language/{lang}', function($lang){
    if(in_array($lang,['en','bn'])){
        session(['locale'=&amp;gt; $lang]);
    }
    return back(); // return to the previous page from where language changed by user
})-&amp;gt;name('change-language');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it’s time to creat language files where we will keep our translations. There are two ways to translate language.One is using translated language in php file or using json file.&lt;/p&gt;

&lt;p&gt;We can use php file for specific purpose. let’s say we need translation only for blog related string for blog feature. This also allow us multi level nested keys for translation mapping.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// for english translation
resources/lang/en/blog.php
return [
    'title' =&amp;gt; 'Title',
    'category' =&amp;gt; 'Category'
];

// for bangla translation
resources/lang/bn/blog.php
return [
    'title' =&amp;gt; 'Title',
    'category' =&amp;gt; 'Category'
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the other hand, we can use a json file to list all our language strings for direct string mapping.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//for bangla translation of strings.
resources/lang/bn.json
{
    "Welcome to Code With Rubab": "কোড উইথ রুবাব এ আপনাকে স্বাগতম"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we will will add language change select option in our welcome blade file. Also translated language will be seen a user changes a language.&lt;/p&gt;

&lt;p&gt;resources/views/welcome.blade.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"&amp;gt;
    {{ session('locale') === 'bn' ? 'বাংলা' : 'English' }}
&amp;lt;/button&amp;gt;
&amp;lt;ul class="dropdown-menu"&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;a class="dropdown-item" href="{{ route('change-language','en') }}"&amp;gt;
            English
        &amp;lt;/a&amp;gt;
    &amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;a class="dropdown-item" href="{{ route('change-language','bn') }}"&amp;gt;
            বাংলা
        &amp;lt;/a&amp;gt;
    &amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;

// translate string based on the selected language
&amp;lt;div&amp;gt;
    {{ __('Welcome to Code With Rubab') }}

    // translate from blog language file
    @lang('blog.title') 
    trans('blog.category')
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bonus:&lt;/p&gt;

&lt;p&gt;Add auto language set based on Country.&lt;/p&gt;

&lt;p&gt;Install the package &lt;a href="https://lyften.com/projects/laravel-geoip/doc/"&gt;geoip&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require torann/geoip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the CACHE_DRIVER=array in env file.&lt;/p&gt;

&lt;p&gt;modify the SetLocale middleware for automatically setting language in the handle function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(is_null(session('locale'))){
    $lang = geoip()-&amp;gt;getLocation()-&amp;gt;country === 'Bangladesh' ? "bn"  : "en";
    session(['locale'=&amp;gt; $lang]);
}
app()-&amp;gt;setLocale(session('locale'));

return $next($request);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the part one for static based translation. In the next part, we will use dynmaic based translation where a blog post will be uploaded in multi language and users will be able to read blog post in different languages.&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>coding</category>
      <category>programming</category>
    </item>
    <item>
      <title>Importance Of Using Log in Your Project</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Sun, 16 Jul 2023 16:02:04 +0000</pubDate>
      <link>https://dev.to/rubab2020/importance-of-using-log-in-your-project-26oo</link>
      <guid>https://dev.to/rubab2020/importance-of-using-log-in-your-project-26oo</guid>
      <description>&lt;p&gt;As a developer you should write Log in your project. It plays a very important role in your project. Some developers don't know the importance so they don't write it or ignore writing proper logs in their projects.&lt;/p&gt;

&lt;p&gt;I have seen the absence of writing logs in small/mid level projects from junior/mid level developers. Even some senior developers don't write it properly. This scenario is very common in single developer based projects or in a freelance based project or in startups. In this article I'm going to show you how to use it properly in your project.&lt;/p&gt;

&lt;p&gt;But first, What is Log?&lt;br&gt;
Log helps developers to track what is happening within your application. When a product goes to production server then we don't know what happened in between a user's request and response. So in order to investigate a failed scenario we need check the Log.&lt;/p&gt;

&lt;p&gt;Some real life scenarios:&lt;/p&gt;

&lt;p&gt;Case One:&lt;br&gt;
When Log is not given: Payment is given for an order from an eCommerce website via payment gateway. Customer got a payment receipt generated from the gateway. Customer sees the transaction is not present after the successful payment. The eCommerce site does not have a log of the payment request so the request data can be found. Just assume how difficult it is to solve this issue. It will require investigating whether the actual customer paid or not, checking customer related data, customer’s concern of his/her payment, several cross check meetings from both companies involving developers, managers, operation team members and other stakeholders. If nothing can be found and the customer’s claim is valid then manually adding the data to a database where tables may have relations for the new payment data. Just think how much time will be wasted for solving the problem where a request and response log would just take a minute to write it.&lt;/p&gt;

&lt;p&gt;Case 2:&lt;br&gt;
When Detailed logs are not provided: Let’s say you have a shipping request. In this case you are a logistics Aggregator. An API request comes from a merchant website for shipping, you process the requested data which goes through some complex logic in your application through several scripts, and at one point it creates a new request data based on the provided request which is then sent over a third party logistic partner that actually takes the order. Based on the third party api's response the aggregator application returns a response to the merchant website. See how complex it is if you don’t log the merchant request, different logic states, log of formatted request and response data of the third party services. If something happens during a shipping order, it will be very hard to identify what went wrong to the request. &lt;/p&gt;

&lt;p&gt;Commonly used Logs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Info&lt;/li&gt;
&lt;li&gt;Debug&lt;/li&gt;
&lt;li&gt;Warning&lt;/li&gt;
&lt;li&gt;Error&lt;/li&gt;
&lt;li&gt;Alert&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are using Laravel then you can use these Log function as below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import the Log Class
use Illuminate\Support\Facades\Log;

Log::emergency($message);
Log::alert($message);
Log::critical($message);
Log::error($message);
Log::warning($message);
Log::notice($message);
Log::info($message);
Log::debug($message);

// Or Without importing the class
\Log::error($message);

//Example
Log::info('place order to partner.');
Log::debug("Processing Payment Payload- " . print_r($input, true));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can structure our Log data and reuse in any file of our project.&lt;br&gt;
First create a class and then add add it under autoload as below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"autoload": {
        .....
        "files": [
            "app/Helpers/CommonHelper.php"
        ]
        .....
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I have created a CommonHelper file and placed inside the app/Helpers directory.&lt;/p&gt;

&lt;p&gt;Inside CommonHelper.php file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Generalize the debug log format.
 */
if (!function_exists('__formatDebugLog')) {
    /**
     * @param string $label
     * @param mixed $data
     * @param string $tag
     * @return string
     */
    function __formatDebugLog($label, $data = null, $tag = '')
    {
        $tag = empty($tag) ? '' : "{$tag} ";

        $data = is_string($data) ? $data : json_encode($data);

        return $tag . $label . ': ' . $data;
    }
}

/**
 * Generalize the log format for exception.
 */
if (!function_exists('__formatExceptionLog')) {
    /**
     * @param Throwable $e
     * @param $class
     * @param $fn
     * @param $tag
     * @return string
     */
    function __formatExceptionLog(Throwable $e, $class, $fn, $tag = '')
    {
        $tag = empty($tag) ? '' : "{$tag} ";
        return $tag . 'Found Exception: ' . $e-&amp;gt;getMessage() . ' [Script: ' . $class . '@' . $fn . '] [Origin: ' . $e-&amp;gt;getFile() . '-' . $e-&amp;gt;getLine() . ']';
    }
}

// Generalize data log format 

if (!function_exists('__formatLogData')) {
    function __formatLogData($data)
    {
        if(is_object($data)){
            $data = (array) $data;
        }

        return $data;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example of usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try{
    Log::error(__formatDebugLog("order placement failed to partner", $order));
} catch (\Throwable $e) {
    Log::error(__formatExceptionLog($e, __CLASS__, __FUNCTION__));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use tag for tacking log data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$tag = isset($request-&amp;gt;merchant_order_id) ? "MER_ORD_ID[{$request-&amp;gt;merchant_order_id}]" : '';

try{
    Log::info("{$tag} Order =&amp;gt; request data: " . json_encode(__formatLogData($this-&amp;gt;all())));
    Log::debug("[{$tag}]: city list load failed");
} catch (\Throwable $e) {
    Log::error(__formatExceptionLog($e, __CLASS__, __FUNCTION__, $tag));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample Log output:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmimbsk7wkv8cn66yvhk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmimbsk7wkv8cn66yvhk.png" alt="Sample Log output" width="800" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be careful when adding a log data. We should not write sensitive data in the scenario when an attacker can steal our log data.&lt;/p&gt;

&lt;p&gt;So, avoid logging sensitive data such as,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Credit card no (use masking if required), CVV of a card. &lt;/li&gt;
&lt;li&gt;Any kind of user login credentials, Token, API Key, API secret etc.&lt;/li&gt;
&lt;li&gt;Plain data of encrypted data.&lt;/li&gt;
&lt;li&gt;Any sensitive information from config data. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>coding</category>
    </item>
    <item>
      <title>Beware of double dollar sign "$$" in a variable in PHP.</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Wed, 12 Jul 2023 11:20:09 +0000</pubDate>
      <link>https://dev.to/rubab2020/beware-of-double-dollar-sign-in-a-variable-in-php-1aa5</link>
      <guid>https://dev.to/rubab2020/beware-of-double-dollar-sign-in-a-variable-in-php-1aa5</guid>
      <description>&lt;p&gt;We all know Dollar sign($) is used to declare a variable in PHP. What if we accidentally type dollar sign two times for a variable. This can potentially affect your expected output.&lt;/p&gt;

&lt;p&gt;For example, let's say we want to encrypt data. The output of the encrypted data will not be the same for variables with single dollar variable ($x) and double dollar variable ($$x) because the $$x (double dollar) is a reference variable. This reference variable is called variable variables in PHP. Variable variables are simply variables whose names are dynamically created by another variable’s value.&lt;/p&gt;

&lt;p&gt;So, we also need to check this kind of mistake while debugging our code if the logic of the code seems alright. &lt;/p&gt;

&lt;p&gt;Happy bug finding!&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>softwareengineering</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build a product with defensive mechanism.</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Mon, 10 Jul 2023 11:04:43 +0000</pubDate>
      <link>https://dev.to/rubab2020/build-a-product-with-a-defensive-mechanism-52cd</link>
      <guid>https://dev.to/rubab2020/build-a-product-with-a-defensive-mechanism-52cd</guid>
      <description>&lt;p&gt;Over 5 crore Bangladeshi citizens' personal data 'exposed' online which is actually a big concern for country. Citizens' personal information, including their full names, phone numbers, email addresses and National Identification (NID) numbers, has been exposed from a Bangladesh government website according to local news paper &lt;br&gt;
&lt;a href="https://www.tbsnews.net/bangladesh/millions-bangladeshi-citizens-data-exposed-online-661958"&gt;The Business Standard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It's sad to see that our personal data has been exposed online. That's why we should not only focus on development rather focus on everything that is a part of a software. We should follow best practices during software development, Code review, proper testing of software, network level security, protection from any malware attack, vulnerability check, Database protection, user roles, user activity track, API Security and so on. There are some companies prove vulnerability check and security related services in this regard.&lt;/p&gt;

&lt;p&gt;We need to understand that the cost of a data breach is fatal than not giving extra time to perform these actions during software development. A great product requires periodically maintaining and upgrading the system after a software release. Let's build a product with a defensive mechanism.&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>databreach</category>
      <category>cybersecurity</category>
      <category>programming</category>
    </item>
    <item>
      <title>We don’t just write computer code, we write business scripts</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Wed, 31 May 2023 05:44:11 +0000</pubDate>
      <link>https://dev.to/rubab2020/we-dont-just-write-computer-code-we-write-business-scripts-2k97</link>
      <guid>https://dev.to/rubab2020/we-dont-just-write-computer-code-we-write-business-scripts-2k97</guid>
      <description>&lt;p&gt;A professional software is built for business purposes. We develop software that can serve millions of users and aim to solve a particular problem to make people’s lives easier. Software features come from many areas such as client’s requirements, business team’s requirements of a organisation, startup project ideas and so on.&lt;/p&gt;

&lt;p&gt;A software can have lots of complex features, dependencies on third party software and so on. It’s so important to understand a business logic properly. Failing to understand business logic leads to rewriting it again thus wasting development time &amp;amp; delaying project deadline. Here are some few tips to follow,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Read the project requirements properly. Understand each business logic carefully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Discuss with your client or project manager if you don’t understand a requirement. Ask question, ask a lot of questions if needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand the relationship among features that can help to architect your project in much better way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get to know about software design patters. Carefully Understand which design pattern is suitable for your project by analyzing the pros and cons of each pattern. Pick the one that suits best for your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Communicate with your peers, project manager &amp;amp; clients frequently. Give update of your work after each chunk of development. Show them the progress and get feedback.&lt;br&gt;
Fail early, fail first. It will help us to avoid making a lot of changes in the end. Talk to them about different topics like arts, sports etc, understand how they think, how they describable a problem. This will help you to quickly understand the requirements and business logic from them.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
      <category>designpatterns</category>
      <category>businesslogic</category>
    </item>
    <item>
      <title>5 Tips to Save Your Software Development Time.</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Mon, 15 May 2023 05:39:32 +0000</pubDate>
      <link>https://dev.to/rubab2020/5-tips-to-save-your-software-development-time-4d09</link>
      <guid>https://dev.to/rubab2020/5-tips-to-save-your-software-development-time-4d09</guid>
      <description>&lt;p&gt;Many Times early stage developers waste their time on solving a problem when they are stuck. Some small strategies can help our things done without wasting our time. Here are some tips to save your time.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Limit your time - Try solving problem for 15-20 minutes. If you can't solve the problem after 15-20 minutes, then it's time to ask someone for help.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take a break - If you are working alone then after 15 minutes take a break, drink water or coffee or stretch your body and walk around the room. Now start working on your problem again. This little break may help you to identify solution for your problem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Talk to someone - If you are working in a team then discuss the problem with one of your team members. This is the fastest way to solve the problem. If you don’t find someone then use Rubber duck debugging technique where you explain your logic to a duck and you may get what went wrong just by explaining you may find the issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Seek help from developers community - Getting response from community and forums take time. If above procedures don't work then wait for communities Help and keep work on other problems. It's better post your issue in multiple platforms to get quick response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Try it later - If you have already spent a huge amount time and nothing seems to be working and deadline is knocking on the door then leave it for now. Better discuss with the Project Manager / client if they can slightly change the requirement or work on it later as this has become a blocker to complete your project.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>tips</category>
      <category>beginners</category>
      <category>career</category>
      <category>development</category>
    </item>
    <item>
      <title>5 Tips to Become a Better Software Developer.</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Mon, 15 May 2023 05:25:16 +0000</pubDate>
      <link>https://dev.to/rubab2020/5-tips-to-become-a-better-software-developer-4o9i</link>
      <guid>https://dev.to/rubab2020/5-tips-to-become-a-better-software-developer-4o9i</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Write clean codes.&lt;/li&gt;
&lt;li&gt;Write maintainable and scalable code.&lt;/li&gt;
&lt;li&gt;Don't use magic numbers in your code.&lt;/li&gt;
&lt;li&gt;Write test codes for testing functionalities of you project.&lt;/li&gt;
&lt;li&gt;See other's code on regular basis. Talk to your peers about techniques/ technologies they use to solve a particular problem.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>developer</category>
      <category>beginners</category>
      <category>tips</category>
      <category>career</category>
    </item>
    <item>
      <title>Date Parse Issue Due to Hidden Character</title>
      <dc:creator>Imran Hossain (Rubab)</dc:creator>
      <pubDate>Mon, 13 Feb 2023 05:14:25 +0000</pubDate>
      <link>https://dev.to/rubab2020/date-parse-issue-due-to-hidden-character-7fj</link>
      <guid>https://dev.to/rubab2020/date-parse-issue-due-to-hidden-character-7fj</guid>
      <description>&lt;p&gt;I have recently encountered a bug where Carbon failed to parse any given date input from datepicker. This issue is generated after some package update in the project. This affected the code line given below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Carbon::parse($request-&amp;gt;fromDate)-&amp;gt;format('Y-m-d H:i:s')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After debugging I found out that a special hidden character (u+202f) is being placed in date time data which should actually be a space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsa772c78qsq5v3tpfk0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsa772c78qsq5v3tpfk0q.png" alt="" width="215" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A very quick solution for this kind of issue can be checking and replacing this type of hidden character.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foh7dxnrq6ab530msnnxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foh7dxnrq6ab530msnnxg.png" alt="" width="316" height="30"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also use regular expression to allow only alphanumeric, space and some special characters to solve this issue.&lt;/p&gt;




&lt;p&gt;Thank you for reading my article. You can join &lt;a href="https://www.facebook.com/groups/codewithrubab"&gt;code with rubab&lt;/a&gt; for web development-related queries &amp;amp; discussions.&lt;/p&gt;

&lt;p&gt;Also, you can find me on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/imran-hossain-rubab/"&gt;Linkedin For Regular Posts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codewithrubab.com/"&gt;My website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.facebook.com/codewithrubab"&gt;My Facebook Page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/@codeWithRubab"&gt;My Youtube Channel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>carbon</category>
      <category>laravel</category>
      <category>php</category>
    </item>
  </channel>
</rss>
