<?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: Ariful Haque Sajib</title>
    <description>The latest articles on DEV Community by Ariful Haque Sajib (@arifulhaque313).</description>
    <link>https://dev.to/arifulhaque313</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%2F3093046%2F2ee913e1-f8c5-4369-b359-cdc7838d76b7.jpg</url>
      <title>DEV Community: Ariful Haque Sajib</title>
      <link>https://dev.to/arifulhaque313</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arifulhaque313"/>
    <language>en</language>
    <item>
      <title>Choosing the Right Database: 3 Questions to End Your Confusion Forever | By Ariful Haque Sajib</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Mon, 02 Mar 2026 16:55:19 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/choosing-the-right-database-3-questions-to-end-your-confusion-forever-by-ariful-haque-sajib-35n5</link>
      <guid>https://dev.to/arifulhaque313/choosing-the-right-database-3-questions-to-end-your-confusion-forever-by-ariful-haque-sajib-35n5</guid>
      <description>&lt;p&gt;Every developer has been there. You’re starting a new project, the terminal is open, and then the big question hits: “Which database should I use?” 🤔&lt;/p&gt;

&lt;p&gt;Should you stick with the reliability of MySQL? Go for the advanced features of PostgreSQL? Or embrace the flexibility of MongoDB?&lt;/p&gt;

&lt;p&gt;I used to spend hours overthinking this. But after building various systems, I realized the answer isn’t about which database is “best” — it’s about which one fits your data. You can end the confusion forever by asking yourself these three simple questions.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Question 1: Is Your Data Structured?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If your data can be neatly organized into tables with fixed rows and columns, and if different data points need to talk to each other (Relations, Foreign Keys, Joins), then a Relational Database (RDBMS) is your go-to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option A: MySQL&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Vibe: The "Old Reliable" of the web.&lt;/li&gt;
&lt;li&gt;Best For: Small to medium-sized projects, CMS (like WordPress), and startups that need to move fast.&lt;/li&gt;
&lt;li&gt;Why Choose It? It's incredibly easy to set up, has massive community support, and is highly optimized for read-heavy applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Option B: PostgreSQL&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Vibe: The "Powerhouse" for perfectionists.&lt;/li&gt;
&lt;li&gt;Best For: Enterprise-level apps, Financial systems (FinTech), and complex data analysis.&lt;/li&gt;
&lt;li&gt;Why Choose It? It handles complex queries and advanced indexing like a champ. Its strict adherence to ACID compliance ensures that your data integrity is never compromised, even during complex transactions.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Question 2: Is Your Data Flexible or Semi-Structured?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;What if your data doesn't fit into a rigid box? What if every record looks a little different, or the structure changes every week?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Winner: MongoDB&lt;/li&gt;
&lt;li&gt;The Vibe: The "Agile" choice for modern apps.&lt;/li&gt;
&lt;li&gt;Best For: Real-time applications, IoT, Content Management, and Social Platforms.&lt;/li&gt;
&lt;li&gt;Why Choose It? MongoDB is a NoSQL database that stores data in JSON-like documents. If you need to store nested data or if you're building a prototype where the requirements are constantly evolving, MongoDB's schema-less nature is a lifesaver.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Question 3: How Much Scale Do You Truly Need?
&lt;/h2&gt;

&lt;p&gt;Scaling isn't just a buzzword; it's a technical requirement that dictates your database's future.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need Simple Vertical Scaling? Both MySQL and PostgreSQL are incredibly capable. With proper indexing and query optimization, they can handle millions of transactions easily.&lt;/li&gt;
&lt;li&gt;Need Effortless Horizontal Scaling? If you expect your data to be spread across many servers globally, MongoDB was built for this. Its "sharding" capabilities make horizontal scaling much more intuitive.&lt;/li&gt;
&lt;li&gt;Need Strong Consistency? For banking or apps where a single cent cannot go missing, PostgreSQL (or MySQL) is superior due to its strong consistency and complex transaction support&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  In Short
&lt;/h2&gt;

&lt;p&gt;🏦 Bank / Fintech → PostgreSQL&lt;br&gt;
📝 Blog / CMS → MySQL&lt;br&gt;
📱 Real-time App বা Social Platform → MongoDB&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thought&lt;/strong&gt;&lt;br&gt;
Don't get paralyzed by choice. Most modern databases are powerful enough to handle 90% of use cases. The "best" database is the one that allows you to ship your product and maintain your data's integrity without pulling your hair out.&lt;/p&gt;




</description>
      <category>database</category>
      <category>mysql</category>
      <category>postgressql</category>
      <category>arifulhaquesajib</category>
    </item>
    <item>
      <title>Threads vs Processes Explained for Beginners with Real-Life Examples | Ariful Haque Sajib</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Mon, 23 Jun 2025 17:05:03 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/threads-vs-processes-explained-for-beginners-with-real-life-examples-ariful-haque-sajib-3lji</link>
      <guid>https://dev.to/arifulhaque313/threads-vs-processes-explained-for-beginners-with-real-life-examples-ariful-haque-sajib-3lji</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. What is a Thread?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
A thread is a line of execution. A running program can have one or more threads that perform tasks.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
You’re listening to music on your computer (one thread) while reading something in your browser (another thread). Both are happening at the same time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. What is a Process?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
A process is an instance of a running program. When you run an app, it becomes a process.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
Opening the calculator is one process. Opening Notepad is another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. What is a Single-Threaded Process?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
A program where only one thread runs is called a single-threaded process.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
One person doing only one task at a time, like only cooking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. What is a Multi-Threaded Process?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
A program where multiple threads run simultaneously is called a multi-threaded process.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
One person cooking, listening to the radio, and talking on the phone — doing three tasks at once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. What is a Main Thread?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
The first thread that starts when a program runs is the main thread.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
A manager starts a task and then assigns parts to others — he is the main thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. What is Thread Safety?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
If multiple threads can access or modify data without causing problems, it’s called thread-safe.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
Several people writing in a diary one by one — no conflicts occur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. What is a Race Condition?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
When multiple threads try to change the same data at the same time, causing unexpected results.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
Two people trying to write with the same pen at once — the writing gets messy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. What is a Deadlock?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
When two threads wait on each other’s resources and neither can continue, it’s a deadlock.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
Two people need each other’s keys but won’t give them up — both get stuck.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. What is Concurrency?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
When multiple tasks start and progress alternately, that’s concurrency.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
You cook and also make tea, switching between the two.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. What is Parallelism?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
When multiple tasks run exactly at the same time, it’s parallelism.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
One person is cooking while another is making tea — both tasks at once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. What is a Thread Pool?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
A collection of pre-created threads that can be reused instead of creating new ones each time.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
A restaurant has waiters on standby — ready when an order comes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. What is Context Switching?&lt;/strong&gt;&lt;br&gt;
Definition:&lt;br&gt;
Switching from one thread to another by saving the current state and loading another’s state.&lt;/p&gt;

&lt;p&gt;Simple Example:&lt;br&gt;
You’re reading a book, get a phone call, talk, and then return to reading. That switch is context switching.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;১. থ্রেড (Thread)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
থ্রেড হলো একটি কাজ চালানোর লাইন। কোনো প্রোগ্রাম চালু হলে সেই প্রোগ্রামে এক বা একাধিক থ্রেড থাকতে পারে যা কাজগুলো চালিয়ে নিয়ে যায়।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
আপনি কম্পিউটারে গান শুনছেন (একটা থ্রেড), একই সাথে ব্রাউজারে কিছু পড়ছেন (আরেকটা থ্রেড)। দুটো কাজ একসাথে হচ্ছে।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;২. প্রসেস (Process)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
প্রসেস হলো একটি চালু প্রোগ্রাম। যখন আপনি কোনো অ্যাপ চালান, তখন সেটি একটি প্রসেস হিসেবে কাজ করে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
আপনি যখন ক্যালকুলেটর ওপেন করেন, তখন সেটি একটি প্রসেস। আর যখন নোটপ্যাড চালান, সেটিও আরেকটি প্রসেস।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৩. সিঙ্গেল থ্রেডেড প্রসেস&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যে প্রোগ্রামে শুধু একটি থ্রেড কাজ করে তাকে সিঙ্গেল থ্রেডেড প্রসেস বলে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
একজন মানুষ এক সময়ে একটি কাজ করছে — যেমন শুধু রান্না করছে, অন্য কিছু না।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৪. মাল্টিথ্রেডেড প্রসেস&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যে প্রোগ্রামে একাধিক থ্রেড একসাথে কাজ করে তাকে মাল্টিথ্রেডেড প্রসেস বলে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
একজন মানুষ একই সময়ে রান্না করছে, রেডিও শুনছে, আর ফোনে কথা বলছে — তিনটা কাজ একসাথে করছে।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৫. মেইন থ্রেড (Main Thread)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
প্রোগ্রাম চালু হলে প্রথম যে থ্রেড শুরু হয়, তাকে মেইন থ্রেড বলে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
কোনো কাজের শুরুতে একজন ম্যানেজার আসেন (মেইন থ্রেড), পরে তিনি অন্যদের (নতুন থ্রেড) ডেকে কাজ ভাগ করে দেন।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৬. থ্রেড সেফটি (Thread Safety)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যদি একাধিক থ্রেড একসাথে কোনো ডাটা বা ফাংশনে কাজ করেও কোনো সমস্যা না হয়, তবে সেটিকে থ্রেড-সেফ বলা হয়।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
একটি ডায়েরিতে একাধিক মানুষ লিখছে, কিন্তু সবাই সময় নিয়ে লিখছে, তাই কিছু গণ্ডগোল হচ্ছে না।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৭. রেস কন্ডিশন (Race Condition)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যখন একাধিক থ্রেড একই সময়ে একটি ডাটা পরিবর্তন করার চেষ্টা করে এবং এতে ভুল হয়, তখন সেটি রেস কন্ডিশন।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
দুজন একসাথে একই কলম দিয়ে লিখতে চাইলে লেখা বিগড়ে যায়।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৮. ডেডলক (Deadlock)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যখন দুটি থ্রেড একে অপরের রিসোর্সের জন্য অপেক্ষা করে এবং কেউই কাজ করতে পারে না, তখন ডেডলক হয়।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
দুজন মানুষ একে অপরের কাছে চাবি চায়, কিন্তু কেউই ছাড়তে রাজি নয় — তাই দুজনেই আটকে যায়।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;৯. কনকারেন্সি (Concurrency)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যখন একাধিক কাজ একসাথে শুরু হয় এবং একটার পর একটা করে চলে, তখন তাকে কনকারেন্সি বলে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
আপনি রান্না করছেন, মাঝে মাঝে চা বানাচ্ছেন — দুটো কাজই চলছে একসাথে, একটু একটু করে।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;১০. প্যারালেলিজম (Parallelism)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
যখন একাধিক কাজ একই সময়ে একসাথে চলে, তখন তাকে প্যারালেলিজম বলে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
একজন রান্না করছে, আরেকজন চা বানাচ্ছে — দুজন দুইটা কাজ করছে একসাথে।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;১১. থ্রেড পুল (Thread Pool)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
একগুচ্ছ থ্রেড তৈরি করে রাখা হয় যাতে প্রয়োজনে সেগুলো ব্যবহার করা যায়, একবার একবার নতুন থ্রেড না বানাতে হয়।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
রেস্টুরেন্টে কিছু ওয়েটার standby থাকে, অর্ডার এলেই তাদের কাজে লাগানো হয়।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;১২. কনটেক্সট সুইচিং (Context Switching)&lt;/strong&gt;&lt;br&gt;
সংজ্ঞা:&lt;br&gt;
এক থ্রেড থেকে অন্য থ্রেডে যাওয়ার জন্য বর্তমান অবস্থা সংরক্ষণ করে নতুন থ্রেড চালু করাকে কনটেক্সট সুইচিং বলে।&lt;/p&gt;

&lt;p&gt;সহজ উদাহরণ:&lt;br&gt;
আপনি বই পড়ছিলেন, হঠাৎ ফোন এল — আপনি পড়া বন্ধ করে ফোনে কথা বললেন। পরে আবার পড়া শুরু করলেন। এই পরিবর্তনটাই কনটেক্সট সুইচিং।&lt;/p&gt;

&lt;p&gt;I’m Md Ariful Haque Sajib, a Software Engineer, specializing in PHP, Laravel, Spring Boot, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.&lt;/p&gt;

&lt;p&gt;📌 Follow me for updates and insights:&lt;br&gt;
🌐 GitHub: &lt;a href="https://github.com/Arifulhaque313" rel="noopener noreferrer"&gt;ArifulHaque313&lt;/a&gt;&lt;br&gt;
🔗 LinkedIn: &lt;a href="https://www.linkedin.com/in/arifulhaque313/" rel="noopener noreferrer"&gt;Md Ariful Haque Sajib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📧 Contact: &lt;a href="mailto:asajib7654@gmail.com"&gt;asajib7654@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📢 Hashtags:&lt;/p&gt;

&lt;h1&gt;
  
  
  Thread #MultiThreading #SingleThread #concurrency #DeadLock
&lt;/h1&gt;

&lt;h1&gt;
  
  
  ArifulHaqueSajib #arifulhaque313 #sajib
&lt;/h1&gt;

&lt;p&gt;Hope this makes it more visually appealing! 😊&lt;/p&gt;

</description>
      <category>threadvsprocess</category>
      <category>threads</category>
      <category>multithreading</category>
    </item>
    <item>
      <title>What is Git Stash ? A Complete Guide by Ariful Haque Sajib</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Sun, 22 Jun 2025 12:56:36 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/what-is-git-stash-a-complete-guide-by-ariful-haque-sajib-3jd8</link>
      <guid>https://dev.to/arifulhaque313/what-is-git-stash-a-complete-guide-by-ariful-haque-sajib-3jd8</guid>
      <description>&lt;p&gt;Learn how to use Git Stash to save uncommitted changes, switch branches, and restore work efficiently. Essential commands &amp;amp; best practices explained.&lt;/p&gt;

&lt;p&gt;Have you ever been in the middle of coding, needed to switch branches, but didn’t want to commit half-finished work? Git Stash is the solution!&lt;/p&gt;

&lt;p&gt;This guide will explain:&lt;br&gt;
✅ What Git Stash is and when to use it&lt;br&gt;
✅ Essential Git Stash commands with examples&lt;br&gt;
✅ Best practices and common pitfalls&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Git Stash?&lt;/strong&gt;&lt;br&gt;
Git Stash temporarily saves your uncommitted changes (modified, staged, or untracked files) so you can switch branches, pull updates, or work on something else without losing progress.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When Should You Use Git Stash?&lt;/strong&gt;&lt;br&gt;
✔ Switching branches with uncommitted changes&lt;br&gt;
✔ Saving work before pulling remote updates&lt;br&gt;
✔ Temporarily storing experimental code&lt;br&gt;
✔ Avoiding unnecessary “WIP” (Work in Progress) commits&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Essential Git Stash Commands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Stash Your Changes&lt;/strong&gt;&lt;br&gt;
Save all modified and staged files (but not untracked files):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save including untracked files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash -u
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save with a custom message for easy identification:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash save "Feature X - WIP"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. List All Stashes&lt;/strong&gt;&lt;br&gt;
View your stash history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stash@{0}: On main: Feature X - WIP  
stash@{1}: On dev: Bugfix Y - partial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Apply (Restore) a Stash&lt;/strong&gt;&lt;br&gt;
Restore the latest stash (keeps it in the stash list):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restore a specific stash (e.g., stash@{1}):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash apply stash@{1}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Pop a Stash (Apply &amp;amp; Delete)&lt;/strong&gt;&lt;br&gt;
Restore the latest stash and remove it from the stash list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Delete a Stash
Remove a specific stash:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash drop stash@{1}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clear all stashes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a Branch from a Stash
If your stash conflicts with current changes, create a new branch:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash branch new-branch-name stash@{1}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Git Stash is a powerful tool for managing unfinished work without cluttering your commit history. Whether you’re switching tasks, pulling updates, or experimenting, stash helps keep your workflow clean.&lt;/p&gt;

&lt;p&gt;I’m Md Ariful Haque Sajib, a Software Engineer, specializing in PHP, Laravel, Spring Boot, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.&lt;/p&gt;

&lt;p&gt;📌 Follow me for updates and insights:&lt;br&gt;
🌐 GitHub: &lt;a href="https://github.com/Arifulhaque313" rel="noopener noreferrer"&gt;ArifulHaque313&lt;/a&gt;&lt;br&gt;
🔗 LinkedIn: &lt;a href="https://www.linkedin.com/in/arifulhaque313/" rel="noopener noreferrer"&gt;Md Ariful Haque Sajib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📧 Contact: &lt;a href="mailto:asajib7654@gmail.com"&gt;asajib7654@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📢 Hashtags:&lt;/p&gt;

&lt;h1&gt;
  
  
  GitStash #Git #Github
&lt;/h1&gt;

&lt;h1&gt;
  
  
  ArifulHaqueSajib #arifulhaque313 #sajib
&lt;/h1&gt;

&lt;p&gt;Hope this makes it more visually appealing! 😊&lt;/p&gt;

</description>
      <category>gitstash</category>
      <category>github</category>
      <category>gitstashcommand</category>
      <category>stashcommands</category>
    </item>
    <item>
      <title>What is git tags ? How to Use Git Tags (Create, List, Push &amp; Delete) — Ariful Haque Sajib</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Sat, 21 Jun 2025 11:47:30 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/what-is-git-tags-git-tags-vs-branchhow-to-use-git-tags-create-list-push-delete-ariful-5he</link>
      <guid>https://dev.to/arifulhaque313/what-is-git-tags-git-tags-vs-branchhow-to-use-git-tags-create-list-push-delete-ariful-5he</guid>
      <description>&lt;p&gt;Learn Git tagging essentials with this step-by-step guide by Ariful Haque Sajib. Understand what Git tags are, why they’re useful, the types of tags (lightweight &amp;amp; annotated), and how to create, list, delete, and push tags efficiently. Perfect for developers mastering Git version control!&lt;/p&gt;

&lt;p&gt;Git tags are a powerful feature that allow you to mark specific points in your repository’s history as important, typically used for release points (v1.0, v2.0, etc.). Here’s everything you need to know about Git tags.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Git Tags?&lt;/strong&gt;&lt;br&gt;
Tags are references to specific points in Git history. Unlike branches, tags are immutable — once created, they don’t move as you add new commits. They’re commonly used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mark release versions (v1.0.0, v2.1.3)&lt;/li&gt;
&lt;li&gt;Create stable points to refer back to&lt;/li&gt;
&lt;li&gt;Provide meaningful names to specific commits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Types of Tags&lt;/strong&gt;&lt;br&gt;
There are two types of Git tags:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lightweight tags: Just a pointer to a specific commit&lt;/li&gt;
&lt;li&gt;Annotated tags: Store additional metadata (tagger name, email, date, message)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why Use Tags?&lt;/strong&gt;&lt;br&gt;
Version control: Clearly mark release versions&lt;br&gt;
Documentation: Annotated tags can include release notes&lt;br&gt;
Deployment: Easily deploy specific versions&lt;br&gt;
Reference: Quickly checkout important points in history&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Useful Git Tag Commands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Tags&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;# Create a lightweight tag
git tag v1.0.0

# Create an annotated tag (recommended for releases)
git tag -a v1.0.0 -m "Version 1.0.0 release"

# Tag a specific commit
git tag -a v1.0.0 abc1234 -m "Version 1.0.0"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Listing Tags&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;# List all tags
git tag

# List tags with pattern matching
git tag -l "v1.*"

# Show tag details
git show v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pushing Tags&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;# Push a specific tag to remote
git push origin v1.0.0

# Push all tags to remote
git push origin --tags
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Checking out Tags&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;# Checkout a tag (creates detached HEAD state)
git checkout v1.0.0

# Create a branch from a tag
git checkout -b version1 v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deleting Tags&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;# Delete local tag
git tag -d v1.0.0

# Delete remote tag
git push origin --delete v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advanced Usage&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;# Sign a tag with GPG
git tag -s v1.0.0 -m "Signed version 1.0.0"

# Verify a signed tag
git tag -v v1.0.0

# List tags with creation dates
git for-each-ref --sort=-taggerdate --format '%(refname:short) %(taggerdate:short)' refs/tag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Git Tag vs Branch: Key Differences&lt;/strong&gt;&lt;br&gt;
Understanding the distinction between tags and branches is essential for effective Git workflow management. Here’s a detailed comparison:&lt;/p&gt;

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

&lt;p&gt;*&lt;em&gt;Example: *&lt;/em&gt;&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Git tags are powerful tools for marking important points in your project’s history. Use annotated tags for releases, follow consistent naming conventions, and integrate them into your development workflow. They provide clear reference points for versions, enable easy rollbacks, and improve team collaboration around releases.&lt;/p&gt;

&lt;p&gt;Remember: Tags are immutable references that help organize your project’s timeline and facilitate better version management.&lt;/p&gt;

&lt;p&gt;I’m Md Ariful Haque Sajib, a Software Engineer 👨‍💻 at Adventure Dhaka Limited, specializing in PHP, Laravel, Spring Boot, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.&lt;/p&gt;

&lt;p&gt;📌 Follow me for updates and insights:&lt;br&gt;
🌐 GitHub: &lt;a href="https://github.com/Arifulhaque313" rel="noopener noreferrer"&gt;ArifulHaque313&lt;/a&gt;&lt;br&gt;
🔗 LinkedIn: &lt;a href="https://www.linkedin.com/in/arifulhaque313/" rel="noopener noreferrer"&gt;Md Ariful Haque Sajib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📧 Contact: &lt;a href="mailto:asajib7654@gmail.com"&gt;asajib7654@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📢 Hashtags:&lt;/p&gt;

&lt;h1&gt;
  
  
  GitTags #Release
&lt;/h1&gt;

&lt;h1&gt;
  
  
  ArifulHaqueSajib #arifulhaque313 #sajib
&lt;/h1&gt;

&lt;p&gt;Hope this makes it more visually appealing! 😊&lt;/p&gt;

</description>
      <category>gittags</category>
      <category>git</category>
      <category>github</category>
      <category>tagscommand</category>
    </item>
    <item>
      <title>Laravel Logging By Ariful Haque Sajib</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Sun, 25 May 2025 13:04:18 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/laravel-logging-by-ariful-haque-sajib-1hd6</link>
      <guid>https://dev.to/arifulhaque313/laravel-logging-by-ariful-haque-sajib-1hd6</guid>
      <description>&lt;p&gt;Learn how to use Laravel logging with Monolog, configure channels (files, Slack, etc.), and use logs for debugging. Step-by-step guide by Ariful Haque Sajib for beginners and advanced developers&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Understanding Laravel's Logging System&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Laravel's logging system is built on top of Monolog, a powerful logging library for PHP. This integration provides a robust foundation with multiple "channels" for directing log messages to different outputs like files, the system error log, or even external services.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Log Levels&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Laravel supports eight log levels, arranged from highest to lowest severity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Emergency — System is unusable&lt;/li&gt;
&lt;li&gt;Alert — Action must be taken immediately&lt;/li&gt;
&lt;li&gt;Critical — Critical conditions&lt;/li&gt;
&lt;li&gt;Error — Error conditions&lt;/li&gt;
&lt;li&gt;Warning — Warning conditions&lt;/li&gt;
&lt;li&gt;Notice — Normal but significant events&lt;/li&gt;
&lt;li&gt;Info — Informational messages&lt;/li&gt;
&lt;li&gt;Debug — Detailed debug information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These levels help categorize log messages based on their importance, making it easier to filter and respond to issues appropriately.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Basic Logging in Laravel&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Writing Log Messages&lt;/strong&gt;&lt;br&gt;
Laravel makes it simple to write log messages. Here’s how to use the most common logging methods:&lt;br&gt;
&lt;/p&gt;

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

// Basic info log
Log::info('User logged in successfully');

// Log with context data
Log::info('User profile updated', ['user_id' =&amp;gt; 123, 'changes' =&amp;gt; ['name', 'email']]);

// Different log levels
Log::emergency('System down');
Log::alert('Database connection failed');
Log::critical('Payment system not responding');
Log::error('Unable to process order #123');
Log::warning('User quota nearly reached');
Log::notice('Scheduled maintenance starting');
Log::info('New user registered');
Log::debug('Query executed in 15ms')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use the global logger() helper function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Simple log message
logger('User logged in successfully');

// With context data
logger('Order processed', ['order_id' =&amp;gt; 456, 'amount' =&amp;gt; 99.99]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing Logs&lt;/strong&gt;&lt;br&gt;
By default, Laravel writes logs to files stored in the storage/logs directory. The default log file is named laravel.log, but this can be configured as we'll see later.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Configuring Laravel Logging&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Configuration File&lt;/strong&gt;&lt;br&gt;
Laravel's logging configuration is located in the config/logging.php file. This file defines the available logging channels and their configurations.&lt;/p&gt;

&lt;p&gt;The key settings in this file include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;default - The default channel used when writing log messages&lt;/li&gt;
&lt;li&gt;channels - An array of available logging channels&lt;/li&gt;
&lt;li&gt;deprecations - Configuration for logging deprecated code usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Available Channel Drivers&lt;/strong&gt;&lt;br&gt;
Laravel supports multiple log channel drivers out of the box:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stack - A wrapper for multiple channels&lt;/li&gt;
&lt;li&gt;single - Single file logger&lt;/li&gt;
&lt;li&gt;daily - Rotates log files daily&lt;/li&gt;
&lt;li&gt;slack - Sends logs to Slack&lt;/li&gt;
&lt;li&gt;papertrail - Sends logs to Papertrail&lt;/li&gt;
&lt;li&gt;syslog - Writes to the system log&lt;/li&gt;
&lt;li&gt;errorlog - Writes to the PHP error_log&lt;/li&gt;
&lt;li&gt;monolog - Custom Monolog handler&lt;/li&gt;
&lt;li&gt;custom - Custom logger using factory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common Configuration Examples&lt;/strong&gt;&lt;br&gt;
Single File Logging&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'single' =&amp;gt; [
    'driver' =&amp;gt; 'single',
    'path' =&amp;gt; storage_path('logs/laravel.log'),
    'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Daily Log Files with Retention&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'daily' =&amp;gt; [
    'driver' =&amp;gt; 'daily',
    'path' =&amp;gt; storage_path('logs/laravel.log'),
    'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
    'days' =&amp;gt; 14, // Keep logs for 14 days
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stack Channel (Multiple Destinations)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'stack' =&amp;gt; [
    'driver' =&amp;gt; 'stack',
    'channels' =&amp;gt; ['single', 'slack'],
    'ignore_exceptions' =&amp;gt; false,
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Slack Notifications for Errors&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'slack' =&amp;gt; [
    'driver' =&amp;gt; 'slack',
    'url' =&amp;gt; env('LOG_SLACK_WEBHOOK_URL'),
    'username' =&amp;gt; 'Laravel Log',
    'emoji' =&amp;gt; ':boom:',
    'level' =&amp;gt; env('LOG_LEVEL', 'critical'),
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Advanced Logging Techniques&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Creating Custom Channels&lt;/strong&gt;&lt;br&gt;
You can create custom logging channels by extending the logging configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// In config/logging.php
'channels' =&amp;gt; [
    // ... other channels

    'important' =&amp;gt; [
        'driver' =&amp;gt; 'single',
        'path' =&amp;gt; storage_path('logs/important.log'),
        'level' =&amp;gt; 'notice',
    ],
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Then use it by specifying the channel:&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;Log::channel('important')-&amp;gt;info('This goes to the important log');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Channel Stacks&lt;/strong&gt;&lt;br&gt;
Channel stacks allow you to broadcast log messages to multiple channels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// In config/logging.php
'critical_logs' =&amp;gt; [
    'driver' =&amp;gt; 'stack',
    'channels' =&amp;gt; ['single', 'slack', 'syslog'],
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use it like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Log::stack(['critical_logs'])-&amp;gt;critical('Major system failure detected');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Contextual Information&lt;/strong&gt;&lt;br&gt;
Adding context to log messages makes debugging easier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Log::info('Order processed', [
    'order_id' =&amp;gt; $order-&amp;gt;id,
    'customer' =&amp;gt; $customer-&amp;gt;email,
    'amount' =&amp;gt; $order-&amp;gt;total,
    'items' =&amp;gt; $order-&amp;gt;items-&amp;gt;count()
]);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Customizing Monolog&lt;/strong&gt;&lt;br&gt;
For advanced customization, you can tap into the Monolog instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'customized' =&amp;gt; [
    'driver' =&amp;gt; 'single',
    'path' =&amp;gt; storage_path('logs/custom.log'),
    'level' =&amp;gt; 'debug',
    'tap' =&amp;gt; [App\Logging\CustomizeFormatter::class],
],

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create the handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Logging;

use Monolog\Formatter\LineFormatter;

class CustomizeFormatter
{
    public function __invoke($logger)
    {
        foreach ($logger-&amp;gt;getHandlers() as $handler) {
            $handler-&amp;gt;setFormatter(new LineFormatter(
                '[%datetime%] %channel%.%level_name%: %message% %context% %extra%'
            ));
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Best Practices for Laravel Logging&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Use Appropriate Log Levels&lt;/strong&gt;&lt;br&gt;
Match the log level to the significance of the event:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use debug for detailed development information&lt;/li&gt;
&lt;li&gt;Use info for general operational events&lt;/li&gt;
&lt;li&gt;Use notice for significant but normal events&lt;/li&gt;
&lt;li&gt;Use warning for non-critical issues that need attention&lt;/li&gt;
&lt;li&gt;Use error and above for failures that need immediate response&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Include Contextual Data&lt;/strong&gt;&lt;br&gt;
Always add relevant context to log messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Bad: Generic message with no context
Log::error('Database error');

// Good: Specific message with context
Log::error('Database query failed', [
    'query' =&amp;gt; $query,
    'error' =&amp;gt; $exception-&amp;gt;getMessage(),
    'user_id' =&amp;gt; auth()-&amp;gt;id()
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Configure Log Rotation&lt;/strong&gt;&lt;br&gt;
For production applications, configure log rotation to manage disk space:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'daily' =&amp;gt; [
    'driver' =&amp;gt; 'daily',
    'path' =&amp;gt; storage_path('logs/laravel.log'),
    'level' =&amp;gt; 'debug',
    'days' =&amp;gt; 7, // Adjust based on your needs
],

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Use Structured Logging&lt;/strong&gt;&lt;br&gt;
When possible, log structured data that's easy to parse and analyze:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Log::info('API Request', [
    'endpoint' =&amp;gt; '/api/users',
    'method' =&amp;gt; 'POST',
    'response_code' =&amp;gt; 200,
    'response_time' =&amp;gt; 45.2, // milliseconds
    'user_agent' =&amp;gt; $request-&amp;gt;userAgent()
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Set Up Real-time Alerts&lt;/strong&gt;&lt;br&gt;
For critical issues, configure channels that notify the team immediately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'slack' =&amp;gt; [
    'driver' =&amp;gt; 'slack',
    'url' =&amp;gt; env('LOG_SLACK_WEBHOOK_URL'),
    'username' =&amp;gt; 'Laravel Error Bot',
    'emoji' =&amp;gt; ':rotating_light:',
    'level' =&amp;gt; 'error', // Only errors and above
],

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Common Logging Scenarios&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Exception Logging&lt;/strong&gt;&lt;br&gt;
Laravel automatically logs unhandled exceptions, but you can manually log exceptions too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    // Some risky operation
} catch (\Exception $e) {
    Log::error('Failed to process payment', [
        'exception' =&amp;gt; $e-&amp;gt;getMessage(),
        'order_id' =&amp;gt; $order-&amp;gt;id
    ]);

    // Handle the exception
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User Activity Logging&lt;br&gt;
Track important user actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Log::info('User updated profile', [
    'user_id' =&amp;gt; $user-&amp;gt;id,
    'changed_fields' =&amp;gt; $changedFields
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Performance Logging&lt;/strong&gt;&lt;br&gt;
Monitor application performance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$startTime = microtime(true);

// Perform operation

$executionTime = microtime(true) - $startTime;
Log::debug('Query execution time', [
    'query' =&amp;gt; $queryString,
    'execution_time' =&amp;gt; $executionTime,
    'rows_returned' =&amp;gt; $results-&amp;gt;count()
]);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;API Interaction Logging&lt;/strong&gt;&lt;br&gt;
Log API requests and responses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Log::info('External API call', [
    'endpoint' =&amp;gt; $url,
    'method' =&amp;gt; 'POST',
    'request_data' =&amp;gt; $requestData,
    'response_code' =&amp;gt; $response-&amp;gt;status(),
    'response_time' =&amp;gt; $responseTime
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Debugging with Logs&lt;/strong&gt;&lt;br&gt;
Using Log Messages for Debugging&lt;br&gt;
When debugging complex issues, strategic log messages can help:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Log::debug('Starting import process');

foreach ($records as $index =&amp;gt; $record) {
    Log::debug("Processing record {$index}", ['data' =&amp;gt; $record]);

    // Process record

    Log::debug("Completed record {$index}");
}

Log::debug('Import process completed', ['total_records' =&amp;gt; count($records)]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Temporary Debug Logging&lt;/strong&gt;&lt;br&gt;
For temporary debugging, you can use the tap helper to log without changing your code flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return tap($result, function ($value) {
    Log::debug('Query result', ['value' =&amp;gt; $value]);
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Logging for Different Environments&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Development Environment&lt;/strong&gt;&lt;br&gt;
In development, you typically want verbose logging:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// .env for development
LOG_CHANNEL=stack
LOG_LEVEL=debug
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Production Environment&lt;br&gt;
In production, focus on important events and manage log size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// .env for production
LOG_CHANNEL=daily
LOG_LEVEL=warning  # Only logs warning and above
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Laravel Logging Demo Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This project demonstrates various Laravel logging features including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Different log levels&lt;/li&gt;
&lt;li&gt;Multiple logging channels&lt;/li&gt;
&lt;li&gt;Custom formatters&lt;/li&gt;
&lt;li&gt;Contextual logging&lt;/li&gt;
&lt;li&gt;Exception logging&lt;/li&gt;
&lt;li&gt;Performance monitoring
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php


// ===================================
// 1. CONFIGURATION FILES
// ===================================

// config/logging.php
return [
    'default' =&amp;gt; env('LOG_CHANNEL', 'stack'),

    'deprecations' =&amp;gt; env('LOG_DEPRECATIONS_CHANNEL', 'null'),

    'channels' =&amp;gt; [
        'stack' =&amp;gt; [
            'driver' =&amp;gt; 'stack',
            'channels' =&amp;gt; ['single'],
            'ignore_exceptions' =&amp;gt; false,
        ],

        'single' =&amp;gt; [
            'driver' =&amp;gt; 'single',
            'path' =&amp;gt; storage_path('logs/laravel.log'),
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
        ],

        'daily' =&amp;gt; [
            'driver' =&amp;gt; 'daily',
            'path' =&amp;gt; storage_path('logs/laravel.log'),
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
            'days' =&amp;gt; 14,
        ],

        // Custom channels for our demo
        'user_activity' =&amp;gt; [
            'driver' =&amp;gt; 'single',
            'path' =&amp;gt; storage_path('logs/user-activity.log'),
            'level' =&amp;gt; 'info',
        ],

        'api_requests' =&amp;gt; [
            'driver' =&amp;gt; 'daily',
            'path' =&amp;gt; storage_path('logs/api-requests.log'),
            'level' =&amp;gt; 'debug',
            'days' =&amp;gt; 7,
        ],

        'performance' =&amp;gt; [
            'driver' =&amp;gt; 'single',
            'path' =&amp;gt; storage_path('logs/performance.log'),
            'level' =&amp;gt; 'debug',
            'tap' =&amp;gt; [App\Logging\PerformanceFormatter::class],
        ],

        'errors' =&amp;gt; [
            'driver' =&amp;gt; 'daily',
            'path' =&amp;gt; storage_path('logs/errors.log'),
            'level' =&amp;gt; 'error',
            'days' =&amp;gt; 30,
        ],

        'security' =&amp;gt; [
            'driver' =&amp;gt; 'single',
            'path' =&amp;gt; storage_path('logs/security.log'),
            'level' =&amp;gt; 'warning',
        ],

        // Example Slack channel (requires webhook URL)
        'slack' =&amp;gt; [
            'driver' =&amp;gt; 'slack',
            'url' =&amp;gt; env('LOG_SLACK_WEBHOOK_URL'),
            'username' =&amp;gt; 'Laravel Logger',
            'emoji' =&amp;gt; ':boom:',
            'level' =&amp;gt; env('LOG_LEVEL', 'critical'),
        ],

        'critical_stack' =&amp;gt; [
            'driver' =&amp;gt; 'stack',
            'channels' =&amp;gt; ['errors', 'slack'],
        ],
    ],
];

// ===================================
// 2. CUSTOM FORMATTER
// ===================================

// app/Logging/PerformanceFormatter.php
namespace App\Logging;

use Monolog\Formatter\LineFormatter;

class PerformanceFormatter
{
    public function __invoke($logger)
    {
        foreach ($logger-&amp;gt;getHandlers() as $handler) {
            $handler-&amp;gt;setFormatter(new LineFormatter(
                "[%datetime%] PERFORMANCE: %message% | Duration: %context.duration%ms | Memory: %context.memory_usage%MB\n"
            ));
        }
    }
}

// ===================================
// 3. LOGGING SERVICE CLASS
// ===================================

// app/Services/LoggingService.php
namespace App\Services;

use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;

class LoggingService
{
    /**
     * Log user activity with context
     */
    public function logUserActivity(string $action, array $context = []): void
    {
        Log::channel('user_activity')-&amp;gt;info($action, array_merge([
            'user_id' =&amp;gt; auth()-&amp;gt;id() ?? 'guest',
            'ip_address' =&amp;gt; request()-&amp;gt;ip(),
            'user_agent' =&amp;gt; request()-&amp;gt;userAgent(),
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString(),
        ], $context));
    }

    /**
     * Log API request with performance metrics
     */
    public function logApiRequest(Request $request, $response, float $duration): void
    {
        Log::channel('api_requests')-&amp;gt;info('API Request', [
            'method' =&amp;gt; $request-&amp;gt;method(),
            'url' =&amp;gt; $request-&amp;gt;fullUrl(),
            'ip' =&amp;gt; $request-&amp;gt;ip(),
            'user_agent' =&amp;gt; $request-&amp;gt;userAgent(),
            'status_code' =&amp;gt; $response-&amp;gt;getStatusCode(),
            'duration_ms' =&amp;gt; round($duration * 1000, 2),
            'memory_usage' =&amp;gt; round(memory_get_peak_usage(true) / 1024 / 1024, 2),
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString(),
        ]);
    }

    /**
     * Log performance metrics
     */
    public function logPerformance(string $operation, float $duration, array $context = []): void
    {
        Log::channel('performance')-&amp;gt;debug($operation, array_merge([
            'duration' =&amp;gt; round($duration * 1000, 2), // Convert to milliseconds
            'memory_usage' =&amp;gt; round(memory_get_peak_usage(true) / 1024 / 1024, 2), // Convert to MB
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString(),
        ], $context));
    }

    /**
     * Log security events
     */
    public function logSecurityEvent(string $event, string $level = 'warning', array $context = []): void
    {
        Log::channel('security')-&amp;gt;{$level}($event, array_merge([
            'ip_address' =&amp;gt; request()-&amp;gt;ip(),
            'user_agent' =&amp;gt; request()-&amp;gt;userAgent(),
            'user_id' =&amp;gt; auth()-&amp;gt;id() ?? 'anonymous',
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString(),
        ], $context));
    }

    /**
     * Log exceptions with full context
     */
    public function logException(\Throwable $exception, array $context = []): void
    {
        Log::channel('errors')-&amp;gt;error('Exception occurred', array_merge([
            'exception_class' =&amp;gt; get_class($exception),
            'message' =&amp;gt; $exception-&amp;gt;getMessage(),
            'file' =&amp;gt; $exception-&amp;gt;getFile(),
            'line' =&amp;gt; $exception-&amp;gt;getLine(),
            'trace' =&amp;gt; $exception-&amp;gt;getTraceAsString(),
            'user_id' =&amp;gt; auth()-&amp;gt;id() ?? 'guest',
            'url' =&amp;gt; request()-&amp;gt;fullUrl(),
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString(),
        ], $context));
    }
}

// ===================================
// 4.CONTROLLER
// ===================================

// app/Http/Controllers/LoggingDemoController.php
namespace App\Http\Controllers;

use App\Services\LoggingService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

class LoggingDemoController extends Controller
{
    protected LoggingService $loggingService;

    public function __construct(LoggingService $loggingService)
    {
        $this-&amp;gt;loggingService = $loggingService;
    }

    /**
     * Demonstrate all log levels
     */
    public function demonstrateLogLevels()
    {
        Log::emergency('System is completely down - EMERGENCY');
        Log::alert('Database connection lost - immediate action required');
        Log::critical('Payment gateway not responding - CRITICAL');
        Log::error('Failed to process user registration');
        Log::warning('User storage quota at 90%');
        Log::notice('Scheduled maintenance completed successfully');
        Log::info('New user registered: john@example.com');
        Log::debug('Query executed successfully in 45ms');

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'All log levels demonstrated. Check your log files!',
            'log_files' =&amp;gt; [
                'main' =&amp;gt; storage_path('logs/laravel.log'),
                'errors' =&amp;gt; storage_path('logs/errors.log'),
            ]
        ]);
    }

    /**
     * Demonstrate contextual logging
     */
    public function demonstrateContextualLogging()
    {
        // User activity logging
        $this-&amp;gt;loggingService-&amp;gt;logUserActivity('Profile Updated', [
            'changed_fields' =&amp;gt; ['name', 'email'],
            'old_email' =&amp;gt; 'old@example.com',
            'new_email' =&amp;gt; 'new@example.com'
        ]);

        // API request simulation
        $startTime = microtime(true);
        sleep(1); // Simulate processing time
        $duration = microtime(true) - $startTime;

        $this-&amp;gt;loggingService-&amp;gt;logApiRequest(
            request(),
            response()-&amp;gt;json(['status' =&amp;gt; 'success']),
            $duration
        );

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'Contextual logging demonstrated',
            'check_files' =&amp;gt; [
                'user_activity' =&amp;gt; storage_path('logs/user-activity.log'),
                'api_requests' =&amp;gt; storage_path('logs/api-requests.log'),
            ]
        ]);
    }

    /**
     * Demonstrate performance logging
     */
    public function demonstratePerformanceLogging()
    {
        // Database query performance
        $startTime = microtime(true);

        // Simulate database operation
        DB::select('SELECT SLEEP(0.5)'); // Simulate slow query

        $duration = microtime(true) - $startTime;

        $this-&amp;gt;loggingService-&amp;gt;logPerformance('Database Query', $duration, [
            'query' =&amp;gt; 'SELECT * FROM users WHERE active = 1',
            'rows_affected' =&amp;gt; 150,
            'slow_query' =&amp;gt; $duration &amp;gt; 0.1 ? 'yes' : 'no'
        ]);

        // File processing performance
        $startTime = microtime(true);

        // Simulate file processing
        for ($i = 0; $i &amp;lt; 10000; $i++) {
            // Simulate processing
        }

        $duration = microtime(true) - $startTime;

        $this-&amp;gt;loggingService-&amp;gt;logPerformance('File Processing', $duration, [
            'files_processed' =&amp;gt; 10000,
            'batch_size' =&amp;gt; 1000
        ]);

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'Performance logging demonstrated',
            'check_file' =&amp;gt; storage_path('logs/performance.log')
        ]);
    }

    /**
     * Demonstrate exception logging
     */
    public function demonstrateExceptionLogging()
    {
        try {
            // Simulate various types of exceptions
            throw new \InvalidArgumentException('Invalid user data provided');
        } catch (\Exception $e) {
            $this-&amp;gt;loggingService-&amp;gt;logException($e, [
                'user_input' =&amp;gt; ['name' =&amp;gt; '', 'email' =&amp;gt; 'invalid-email'],
                'validation_errors' =&amp;gt; ['name' =&amp;gt; 'required', 'email' =&amp;gt; 'invalid format']
            ]);
        }

        try {
            // Simulate database exception
            throw new \PDOException('Connection to database failed');
        } catch (\Exception $e) {
            $this-&amp;gt;loggingService-&amp;gt;logException($e, [
                'database_host' =&amp;gt; 'localhost',
                'retry_attempts' =&amp;gt; 3
            ]);
        }

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'Exception logging demonstrated',
            'check_file' =&amp;gt; storage_path('logs/errors.log')
        ]);
    }

    /**
     * Demonstrate security logging
     */
    public function demonstrateSecurityLogging()
    {
        // Failed login attempt
        $this-&amp;gt;loggingService-&amp;gt;logSecurityEvent('Failed Login Attempt', 'warning', [
            'attempted_email' =&amp;gt; 'admin@example.com',
            'failed_attempts_count' =&amp;gt; 3,
            'locked_out' =&amp;gt; false
        ]);

        // Suspicious activity
        $this-&amp;gt;loggingService-&amp;gt;logSecurityEvent('Suspicious Activity Detected', 'alert', [
            'activity_type' =&amp;gt; 'Multiple rapid requests',
            'request_count' =&amp;gt; 100,
            'time_window' =&amp;gt; '1 minute',
            'blocked' =&amp;gt; true
        ]);

        // Password change
        $this-&amp;gt;loggingService-&amp;gt;logSecurityEvent('Password Changed', 'notice', [
            'user_email' =&amp;gt; 'user@example.com',
            'password_strength' =&amp;gt; 'strong'
        ]);

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'Security logging demonstrated',
            'check_file' =&amp;gt; storage_path('logs/security.log')
        ]);
    }

    /**
     * Demonstrate channel-specific logging
     */
    public function demonstrateChannelLogging()
    {
        // Log to specific channels
        Log::channel('user_activity')-&amp;gt;info('User logged in', ['user_id' =&amp;gt; 123]);
        Log::channel('api_requests')-&amp;gt;debug('API call made', ['endpoint' =&amp;gt; '/api/users']);
        Log::channel('errors')-&amp;gt;error('Payment processing failed', ['order_id' =&amp;gt; 456]);
        Log::channel('security')-&amp;gt;warning('Brute force attempt detected');

        // Log to multiple channels using stack
        Log::stack(['errors', 'slack'])-&amp;gt;critical('System critical error detected');

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'Channel-specific logging demonstrated',
            'channels_used' =&amp;gt; ['user_activity', 'api_requests', 'errors', 'security', 'critical_stack']
        ]);
    }

    /**
     * Demonstrate structured logging for analytics
     */
    public function demonstrateStructuredLogging()
    {
        // E-commerce events
        Log::info('Product Purchased', [
            'event_type' =&amp;gt; 'purchase',
            'product_id' =&amp;gt; 'prod_123',
            'product_name' =&amp;gt; 'Laravel Course',
            'price' =&amp;gt; 99.99,
            'currency' =&amp;gt; 'USD',
            'customer_id' =&amp;gt; 'cust_456',
            'payment_method' =&amp;gt; 'credit_card',
            'discount_applied' =&amp;gt; 10.00,
            'final_amount' =&amp;gt; 89.99,
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString()
        ]);

        // User behavior tracking
        Log::info('Page View', [
            'event_type' =&amp;gt; 'page_view',
            'page_url' =&amp;gt; '/products/laravel-course',
            'referrer' =&amp;gt; 'https://google.com',
            'session_id' =&amp;gt; 'sess_789',
            'user_id' =&amp;gt; auth()-&amp;gt;id() ?? null,
            'device_type' =&amp;gt; 'desktop',
            'browser' =&amp;gt; 'Chrome',
            'country' =&amp;gt; 'US',
            'timestamp' =&amp;gt; now()-&amp;gt;toISOString()
        ]);

        return response()-&amp;gt;json([
            'message' =&amp;gt; 'Structured logging for analytics demonstrated',
            'note' =&amp;gt; 'Check logs for structured data that can be easily parsed for analytics'
        ]);
    }
}

// ===================================
// 5. MIDDLEWARE FOR AUTOMATIC LOGGING
// ===================================

// app/Http/Middleware/LogRequests.php
namespace App\Http\Middleware;

use App\Services\LoggingService;
use Closure;
use Illuminate\Http\Request;

class LogRequests
{
    protected LoggingService $loggingService;

    public function __construct(LoggingService $loggingService)
    {
        $this-&amp;gt;loggingService = $loggingService;
    }

    public function handle(Request $request, Closure $next)
    {
        $startTime = microtime(true);

        $response = $next($request);

        $duration = microtime(true) - $startTime;

        // Log API requests automatically
        if ($request-&amp;gt;is('api/*')) {
            $this-&amp;gt;loggingService-&amp;gt;logApiRequest($request, $response, $duration);
        }

        return $response;
    }
}

// ===================================
// 6. ARTISAN COMMAND FOR LOG ANALYSIS
// ===================================

// app/Console/Commands/AnalyzeLogs.php
namespace App\Console\Commands;

use Illuminate\Console\Command;

class AnalyzeLogs extends Command
{
    protected $signature = 'logs:analyze {--file=laravel.log}';
    protected $description = 'Analyze log files and provide statistics';

    public function handle()
    {
        $filename = $this-&amp;gt;option('file');
        $filepath = storage_path("logs/{$filename}");

        if (!file_exists($filepath)) {
            $this-&amp;gt;error("Log file {$filename} not found!");
            return 1;
        }

        $content = file_get_contents($filepath);
        $lines = explode("\n", $content);

        $stats = [
            'total_lines' =&amp;gt; count($lines),
            'emergency' =&amp;gt; substr_count($content, '.EMERGENCY:'),
            'alert' =&amp;gt; substr_count($content, '.ALERT:'),
            'critical' =&amp;gt; substr_count($content, '.CRITICAL:'),
            'error' =&amp;gt; substr_count($content, '.ERROR:'),
            'warning' =&amp;gt; substr_count($content, '.WARNING:'),
            'notice' =&amp;gt; substr_count($content, '.NOTICE:'),
            'info' =&amp;gt; substr_count($content, '.INFO:'),
            'debug' =&amp;gt; substr_count($content, '.DEBUG:'),
        ];

        $this-&amp;gt;info("Log Analysis for {$filename}");
        $this-&amp;gt;line("=====================================");
        $this-&amp;gt;line("Total Lines: {$stats['total_lines']}");
        $this-&amp;gt;line("");
        $this-&amp;gt;line("Log Level Distribution:");
        foreach (['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'] as $level) {
            $count = $stats[$level];
            $percentage = $stats['total_lines'] &amp;gt; 0 ? round(($count / $stats['total_lines']) * 100, 2) : 0;
            $this-&amp;gt;line(sprintf("%-10s: %5d (%5.2f%%)", ucfirst($level), $count, $percentage));
        }

        return 0;
    }
}

// ===================================
// 7. ROUTES
// ===================================

// routes/web.php
use App\Http\Controllers\LoggingDemoController;

Route::prefix('logging-demo')-&amp;gt;group(function () {
    Route::get('/', function () {
        return view('logging-demo');
    });

    Route::get('/levels', [LoggingDemoController::class, 'demonstrateLogLevels']);
    Route::get('/contextual', [LoggingDemoController::class, 'demonstrateContextualLogging']);
    Route::get('/performance', [LoggingDemoController::class, 'demonstratePerformanceLogging']);
    Route::get('/exceptions', [LoggingDemoController::class, 'demonstrateExceptionLogging']);
    Route::get('/security', [LoggingDemoController::class, 'demonstrateSecurityLogging']);
    Route::get('/channels', [LoggingDemoController::class, 'demonstrateChannelLogging']);
    Route::get('/structured', [LoggingDemoController::class, 'demonstrateStructuredLogging']);
});

// ===================================
// 8. DEMO VIEW
// ===================================

// resources/views/logging-demo.blade.php
/*
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Laravel Logging Demo&amp;lt;/title&amp;gt;
    &amp;lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container mt-5"&amp;gt;
        &amp;lt;h1&amp;gt;Laravel Logging Demo&amp;lt;/h1&amp;gt;
        &amp;lt;p&amp;gt;Click the buttons below to test different logging features. Check your log files in &amp;lt;code&amp;gt;storage/logs/&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;

        &amp;lt;div class="row"&amp;gt;
            &amp;lt;div class="col-md-6"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Log Levels Demo&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test all 8 log levels&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-primary" onclick="testEndpoint('/logging-demo/levels')"&amp;gt;Test Log Levels&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="col-md-6"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Contextual Logging&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test logging with context data&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-success" onclick="testEndpoint('/logging-demo/contextual')"&amp;gt;Test Contextual&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="row mt-3"&amp;gt;
            &amp;lt;div class="col-md-6"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Performance Logging&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test performance monitoring&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-info" onclick="testEndpoint('/logging-demo/performance')"&amp;gt;Test Performance&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="col-md-6"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Exception Logging&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test exception handling&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-warning" onclick="testEndpoint('/logging-demo/exceptions')"&amp;gt;Test Exceptions&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="row mt-3"&amp;gt;
            &amp;lt;div class="col-md-6"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Security Logging&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test security event logging&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-danger" onclick="testEndpoint('/logging-demo/security')"&amp;gt;Test Security&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="col-md-6"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Channel Logging&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test different log channels&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-secondary" onclick="testEndpoint('/logging-demo/channels')"&amp;gt;Test Channels&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="row mt-3"&amp;gt;
            &amp;lt;div class="col-md-12"&amp;gt;
                &amp;lt;div class="card"&amp;gt;
                    &amp;lt;div class="card-body"&amp;gt;
                        &amp;lt;h5&amp;gt;Structured Logging&amp;lt;/h5&amp;gt;
                        &amp;lt;p&amp;gt;Test structured logging for analytics&amp;lt;/p&amp;gt;
                        &amp;lt;button class="btn btn-dark" onclick="testEndpoint('/logging-demo/structured')"&amp;gt;Test Structured&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="mt-4"&amp;gt;
            &amp;lt;h3&amp;gt;Response:&amp;lt;/h3&amp;gt;
            &amp;lt;pre id="response" class="bg-light p-3"&amp;gt;&amp;lt;/pre&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script&amp;gt;
        function testEndpoint(url) {
            fetch(url)
                .then(response =&amp;gt; response.json())
                .then(data =&amp;gt; {
                    document.getElementById('response').textContent = JSON.stringify(data, null, 2);
                })
                .catch(error =&amp;gt; {
                    document.getElementById('response').textContent = 'Error: ' + error.message;
                });
        }
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
*/

// ===================================
// 9. ENVIRONMENT CONFIGURATION
// ===================================

// .env additions
/*
# Logging Configuration
LOG_CHANNEL=stack
LOG_LEVEL=debug

# Optional: Slack webhook for critical alerts
LOG_SLACK_WEBHOOK_URL=your_slack_webhook_url_here

# Database logging (if using database driver)
LOG_DATABASE_CONNECTION=mysql
LOG_DATABASE_TABLE=logs
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Installation Instructions&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;1. Create a new Laravel project:
   composer create-project laravel/laravel logging-demo

2. Copy the files above to their respective locations:
   - config/logging.php (replace existing)
   - app/Services/LoggingService.php
   - app/Http/Controllers/LoggingDemoController.php
   - app/Http/Middleware/LogRequests.php
   - app/Console/Commands/AnalyzeLogs.php
   - resources/views/logging-demo.blade.php
   - Add routes to routes/web.php

3. Create the custom formatter directory and file:
   mkdir -p app/Logging
   # Add PerformanceFormatter.php

4. Register the middleware in app/Http/Kernel.php:
   protected $routeMiddleware = [
       // ... other middleware
       'log.requests' =&amp;gt; \App\Http\Middleware\LogRequests::class,
   ];

5. Create log directories (Laravel will create them automatically, but you can pre-create):
   mkdir -p storage/logs

6. Run the application:
   php artisan serve

7. Visit http://localhost:8000/logging-demo to test the logging features

8. Analyze logs using the custom command:
   php artisan logs:analyze
   php artisan logs:analyze --file=user-activity.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Feature Demonstrated:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ All 8 log levels (emergency, alert, critical, error, warning, notice, info, debug)&lt;br&gt;
✅ Multiple logging channels (single, daily, custom)&lt;br&gt;
✅ Contextual logging with structured data&lt;br&gt;
✅ Performance monitoring and logging&lt;br&gt;
✅ Exception logging with full context&lt;br&gt;
✅ Security event logging&lt;br&gt;
✅ Custom log formatters&lt;br&gt;
✅ Middleware for automatic request logging&lt;br&gt;
✅ Artisan command for log analysis&lt;br&gt;
✅ Web interface for testing all features&lt;br&gt;
✅ Different log files for different purposes&lt;br&gt;
✅ Stack channels for broadcasting to multiple destinations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LOG FILES CREATED:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;storage/logs/laravel.log (main application log)&lt;/li&gt;
&lt;li&gt;storage/logs/user-activity.log (user actions)&lt;/li&gt;
&lt;li&gt;storage/logs/api-requests.log (API calls, rotated daily)&lt;/li&gt;
&lt;li&gt;storage/logs/performance.log (performance metrics)&lt;/li&gt;
&lt;li&gt;storage/logs/errors.log (errors only, rotated daily)&lt;/li&gt;
&lt;li&gt;storage/logs/security.log (security events)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Laravel's logging system offers powerful capabilities for tracking application behavior and diagnosing issues. By understanding the different log levels, channels, and configuration options, you can implement an effective logging strategy that provides the right information when you need it.&lt;/p&gt;

&lt;p&gt;For the complete source code, visit:&lt;br&gt;
📂 Git Repository: &lt;a href="https://github.com/Arifulhaque313/laravel-log-master.git" rel="noopener noreferrer"&gt;laravel-log-master&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m Md Ariful Haque Sajib, a Software Engineer 👨‍💻 at Adventure Dhaka Limited, specializing in PHP, Laravel, Spring Boot, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.&lt;/p&gt;

&lt;p&gt;📌 Follow me for updates and insights:&lt;br&gt;
🌐 GitHub: &lt;a href="https://github.com/Arifulhaque313" rel="noopener noreferrer"&gt;ArifulHaque313&lt;/a&gt;&lt;br&gt;
🔗 LinkedIn: &lt;a href="https://www.linkedin.com/in/arifulhaque313/" rel="noopener noreferrer"&gt;Md Ariful Haque Sajib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📧 Contact: &lt;a href="mailto:asajib7654@gmail.com"&gt;asajib7654@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📢 Hashtags:&lt;/p&gt;

&lt;h1&gt;
  
  
  laravel_logging #laravel#ArifulHaque313 #Ariful_Haque_Sajib #ariful_haque #sajib
&lt;/h1&gt;

&lt;p&gt;Hope this makes it more visually appealing! 😊&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>logging</category>
      <category>monolog</category>
      <category>arifulhaque313</category>
    </item>
    <item>
      <title>Dockerize Laravel Vue Application! - By Ariful Haque Sajib</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Sat, 03 May 2025 07:35:58 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/dockerize-laravel-vue-application-by-ariful-haque-sajib-gl0</link>
      <guid>https://dev.to/arifulhaque313/dockerize-laravel-vue-application-by-ariful-haque-sajib-gl0</guid>
      <description>&lt;p&gt;Dockerize laravel vue application — by Ariful Haque Sajib .&lt;br&gt;
In this blog, I’ll walk you through setting up a Laravel 11 and Vue.js 3 with Inertia.js project in a Dockerized environment. The setup orchestrates PHP, NGINX, and MySQL services, creating a smooth development experience. Let’s break it all down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Folder Structure&lt;/strong&gt;&lt;br&gt;
Here’s the folder structure for our project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6t4l9vn9thocpa7nq1q.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6t4l9vn9thocpa7nq1q.webp" alt=" " width="766" height="772"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This structure keeps our Docker-specific files (docker/) separate from the application code (src/). The src/ The folder contains both the Laravel backend and the Vue.js frontend, which are integrated with Breeze for authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Collapse&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzuj0l9obphqf9lyb6s85.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzuj0l9obphqf9lyb6s85.webp" alt=" " width="270" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Setting Up Laravel and Vue.js&lt;/strong&gt;&lt;br&gt;
I use the Laravel Global installer to install the Laravel Vue Inertia application using the steps below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fniad5oh3zsm2unfs4twu.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fniad5oh3zsm2unfs4twu.webp" alt=" " width="800" height="833"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. docker-compose.yml&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;docker-compose.yml defines and configures three essential services: PHP, NGINX, and MySQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.8'

services:
  app:
    build:
      context: ./docker/php
    container_name: laravel-vue-app
    volumes:
      - ./src:/var/www/html
    ports:
      - "9000:9000"
    networks:
      - laravel

  web:
    image: nginx:latest
    container_name: laravel-vue-nginx
    ports:
      - "8081:80"
    volumes:
      - ./src:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app
    networks:
      - laravel

  db:
    image: mysql:8.0
    container_name: laravel-vue-db
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: laravel
      MYSQL_USER: laravel
      MYSQL_PASSWORD: laravel
    volumes:
      - db-data:/var/lib/mysql
    ports:
      - "3307:3306"
    networks:
      - laravel

volumes:
  db-data:

networks:
  laravel:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PHP Service (app):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Uses the Dockerfile in docker/php to build the PHP image.&lt;br&gt;
Mounts the src/ folder to /var/www/html inside the container for live syncing.&lt;br&gt;
Exposes port 9000 for PHP-FPM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NGINX Service (web):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Serves the Laravel application from /var/www/html/public.&lt;br&gt;
Maps the host port 8081 to the container port 80.&lt;br&gt;
Relies on a custom configuration file default.conf.&lt;br&gt;
MySQL Service (db):&lt;/p&gt;

&lt;p&gt;Runs MySQL version 8.0.&lt;br&gt;
Sets up environment variables for database credentials.&lt;br&gt;
Stores data in a Docker-managed volume db-data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Networks and Volumes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A custom laravel network connects all services.&lt;/li&gt;
&lt;li&gt;A named volume db-data persists the MySQL database data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. PHP Dockerfile&lt;/strong&gt;&lt;br&gt;
The Dockerfile in docker/php/ defines the PHP environment for Laravel.&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-fpm

# Install required dependencies
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y \
    git \
    unzip \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    libzip-dev \
    &amp;amp;&amp;amp; docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# Install Composer
COPY --from=composer:2.6 /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Base Image:&lt;/strong&gt; Uses the official php:8.2-fpm image optimized for Laravel.&lt;br&gt;
&lt;strong&gt;2. Dependencies:&lt;/strong&gt; Installs required extensions like pdo_mysql for MySQL, gd for image processing, and zip for file compression.&lt;br&gt;
&lt;strong&gt;3. Composer:&lt;/strong&gt; Adds Composer for dependency management.&lt;br&gt;
&lt;strong&gt;4. Working Directory:&lt;/strong&gt; Sets the working directory to /var/www/html.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. NGINX Configuration&lt;/strong&gt;&lt;br&gt;
The NGINX configuration file default.conf is placed inside docker/nginx/.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name localhost;
    index index.php index.html;
    root /var/www/html/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Root Directory: Points to Laravel’s public/ folder.&lt;/li&gt;
&lt;li&gt;PHP Requests: Forwards .php requests to the PHP service (app) on port 9000.&lt;/li&gt;
&lt;li&gt;Security: Denies access to hidden files (e.g., .htaccess).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Environment Setup .env&lt;/strong&gt;&lt;br&gt;
copy and paste in Laravel .env file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Running the Docker Containers&lt;/strong&gt;&lt;br&gt;
Start the Docker services with docker-compose:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Access the Application:&lt;br&gt;
Laravel App: &lt;a href="http://localhost:8081" rel="noopener noreferrer"&gt;http://localhost:8081&lt;/a&gt;&lt;br&gt;
MySQL: Accessible on port 3307.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Commands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start containers&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Stop containers&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;View container logs&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Access PHP container shell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose exec laravel-vue-app bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List running containers&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This setup ensures that Laravel and Vue.js run seamlessly in a Dockerized environment. It separates concerns, making it easy to manage and scale. With services like PHP, NGINX, and MySQL running in isolated containers, your development workflow becomes efficient and predictable.&lt;/p&gt;

&lt;p&gt;Feel free to tweak this setup based on your project’s needs. Happy coding! 🚀&lt;/p&gt;

&lt;p&gt;For the complete source code, visit:&lt;br&gt;
📂 Git Repository: &lt;a href="https://github.com/Arifulhaque313/dockerize-laravel-vue-app.git" rel="noopener noreferrer"&gt;dockerize-laravel-vue-app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m Md Ariful Haque Sajib, a Software Engineer 👨‍💻 at Adventure Dhaka Limited, specializing in PHP, Laravel, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.&lt;/p&gt;

&lt;p&gt;📌 Follow me for updates and insights:&lt;br&gt;
🌐 GitHub: ArifulHaque313&lt;br&gt;
🔗 LinkedIn: Md Ariful Haque Sajib&lt;/p&gt;

&lt;p&gt;📧 Contact: &lt;a href="mailto:asajib7654@gmail.com"&gt;asajib7654@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📢 Hashtags:&lt;/p&gt;

&lt;h1&gt;
  
  
  ArifulHaque313 #Ariful_Haque_Sajib #ariful_haque #sajib #LaravelSitemap
&lt;/h1&gt;

&lt;p&gt;Hope this makes it more visually appealing! 😊&lt;/p&gt;

</description>
      <category>docker</category>
      <category>laravel</category>
      <category>laravedocker</category>
    </item>
    <item>
      <title>Running MongoDB in Docker: A Simple Guide</title>
      <dc:creator>Ariful Haque Sajib</dc:creator>
      <pubDate>Sat, 26 Apr 2025 11:00:52 +0000</pubDate>
      <link>https://dev.to/arifulhaque313/running-mongodb-in-docker-a-simple-guide-1280</link>
      <guid>https://dev.to/arifulhaque313/running-mongodb-in-docker-a-simple-guide-1280</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38g0c40cvod3cxp9he5p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38g0c40cvod3cxp9he5p.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Running MongoDB in Docker: A Simple Guide By Md Ariful Haque Sajib (arifulhaque313)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Steps
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Setting Up MongoDB
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pull the MongoDB image&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker pull mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run MongoDB container&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker run &lt;span class="nt"&gt;--name&lt;/span&gt; mongodb &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 27017:27017 mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This runs MongoDB on port 27017&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check running containers&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Connect to MongoDB&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; mongodb mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Connect to MongoDB shell&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; mongodb mongosh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Essential MongoDB Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Basic Database Operations
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Show all databases&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   show dbs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use a database&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   use db_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Show collections&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   show collections
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a database&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   db.createDatabase("database_name")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Delete a database&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   db.dropDatabase("database_name")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Working with Collections and Documents
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create collection&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   db.createCollection("collectionName")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Insert documents&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   db.collection_name.insertOne({name: "Md Ariful Haque Sajib"})
   db.collection_name.insertMany([{name: "John"}, {name: "Sarah"}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Update document&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   db.users.updateOne({name: "Ariful Haque"}, {$set: {age: 27}})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Delete document&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   db.users.deleteOne({name: "Ariful Haque"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data Persistence
&lt;/h2&gt;

&lt;p&gt;For keeping your data when container restarts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; mongodb &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 27017:27017 &lt;span class="nt"&gt;-v&lt;/span&gt; /your/local/path:/data/db mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Enabling Security
&lt;/h2&gt;

&lt;p&gt;Create MongoDB with authentication:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; mongodb &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 27017:27017 &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MONGO_INITDB_ROOT_USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;admin &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MONGO_INITDB_ROOT_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;password mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;









&lt;p&gt;I have a project simple project on express js and mongoDB. You can Check out,&lt;br&gt;
📂 Git Repository: Crud-API-Mongo-Express&lt;/p&gt;




&lt;p&gt;I'm Md Ariful Haque Sajib, a Software Engineer 👨‍💻. Specializing in PHP, Laravel, Vue.js, and React.js. With expertise in E-commerce, Payment Gateways, APIs, various Management and Finance-based software. I am passionate about 🧠 learning and delivering 🌟 high-quality solutions.&lt;/p&gt;




&lt;p&gt;📌 Follow me for updates and insights:&lt;br&gt;
🌐 GitHub: ArifulHaque313&lt;br&gt;
🔗 LinkedIn: Md Ariful Haque Sajib&lt;br&gt;
📧 Contact: &lt;a href="mailto:asajib7654@gmail.com"&gt;asajib7654@gmail.com&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;📢 Hashtags:&lt;br&gt;
 #Ariful_Haque_Sajib #MongoDB #Docker #Database #WebDev #arifulhaque313&lt;br&gt;
Hope this makes it more visually appealing! 😊&lt;/p&gt;

</description>
      <category>docker</category>
      <category>mongodb</category>
      <category>database</category>
      <category>arifulhaque</category>
    </item>
  </channel>
</rss>
