<?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: Danish</title>
    <description>The latest articles on DEV Community by Danish (@danish).</description>
    <link>https://dev.to/danish</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%2F932375%2Fe3fe1a61-7179-4eff-97b6-184a1d4e30f4.jpg</url>
      <title>DEV Community: Danish</title>
      <link>https://dev.to/danish</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danish"/>
    <language>en</language>
    <item>
      <title>Converting CSV to PDF HTML JSON &amp; SQL</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Thu, 14 Aug 2025 08:19:31 +0000</pubDate>
      <link>https://dev.to/danish/converting-csv-to-pdf-html-json-sql-2733</link>
      <guid>https://dev.to/danish/converting-csv-to-pdf-html-json-sql-2733</guid>
      <description>&lt;p&gt;CSV is simple, portable, and everywhere—but raw grids rarely tell the story on their own. Converting CSV into richer formats helps you present, publish, integrate, or load data into apps and databases. Below is a practical, example‑driven guide you can use right away.&lt;/p&gt;

&lt;p&gt;Starter dataset used in examples&lt;/p&gt;

&lt;p&gt;Here’s a tiny CSV we would convert in multiple ways:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;order_id,customer,amount,date,paid&lt;br&gt;
1001,Asha,49.99,2025-07-31,true&lt;br&gt;
1002,Omar,125.00,2025-08-01,false&lt;br&gt;
1003,Meera,75.50,2025-08-01,true&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
CSV to PDF&lt;br&gt;
Use this when you need a polished, shareable report: invoices, statements, dashboards.&lt;/p&gt;

&lt;p&gt;Approaches&lt;br&gt;
Direct table rendering: Quick export of a table with minimal styling.&lt;/p&gt;

&lt;p&gt;HTML-to-PDF pipeline: Generate an HTML report (with CSS) then print to PDF for pixel‑perfect control.&lt;/p&gt;

&lt;p&gt;Programmatic report layouts: Build page headers/footers, pagination, totals, and charts in code.&lt;/p&gt;

&lt;p&gt;`import pandas as pd&lt;br&gt;
from weasyprint import HTML, CSS&lt;/p&gt;

&lt;p&gt;df = pd.read_csv("orders.csv")&lt;br&gt;
html = f"""&lt;br&gt;
&amp;lt;!doctype html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;br&gt;
  &lt;br&gt;
  &amp;lt;br&amp;gt;
    body {{ font-family: Arial, sans-serif; margin: 24px; }}&amp;lt;br&amp;gt;
    h1 {{ margin-bottom: 8px; }}&amp;lt;br&amp;gt;
    table {{ border-collapse: collapse; width: 100%; }}&amp;lt;br&amp;gt;
    th, td {{ border: 1px solid #ddd; padding: 8px; font-size: 12px; }}&amp;lt;br&amp;gt;
    th {{ background: #f5f5f5; text-align: left; }}&amp;lt;br&amp;gt;
    tfoot td {{ font-weight: bold; }}&amp;lt;br&amp;gt;
  &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;h1&gt;Orders Report&lt;/h1&gt;
&lt;br&gt;
  {df.to_html(index=False)}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
"""&lt;br&gt;
HTML(string=html).write_pdf("orders.pdf")&lt;br&gt;
`&lt;br&gt;
What it does: Reads CSV, renders a styled HTML table, prints it to PDF.

&lt;p&gt;Why it’s nice: Full CSS support; easy to brand.&lt;/p&gt;

&lt;p&gt;Node.js (Puppeteer: HTML template → PDF)&lt;/p&gt;

&lt;p&gt;`const fs = require('fs');&lt;br&gt;
const Papa = require('papaparse');&lt;br&gt;
const puppeteer = require('puppeteer');&lt;/p&gt;

&lt;p&gt;(async () =&amp;gt; {&lt;br&gt;
  const csv = fs.readFileSync('orders.csv', 'utf8');&lt;br&gt;
  const { data } = Papa.parse(csv, { header: true, dynamicTyping: true });&lt;/p&gt;

&lt;p&gt;const rows = data.map(r =&amp;gt; &lt;code&gt;&lt;br&gt;
    &amp;lt;tr&amp;gt;&lt;br&gt;
      &amp;lt;td&amp;gt;${r.order_id}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;${r.customer}&amp;lt;/td&amp;gt;&lt;br&gt;
      &amp;lt;td&amp;gt;${r.amount}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;${r.date}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;${r.paid}&amp;lt;/td&amp;gt;&lt;br&gt;
    &amp;lt;/tr&amp;gt;&lt;/code&gt;).join('');&lt;/p&gt;

&lt;p&gt;const html = &lt;code&gt;&lt;br&gt;
  &amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;style&amp;gt;&lt;br&gt;
    body { font-family: Arial, sans-serif; margin: 24px; }&lt;br&gt;
    table { border-collapse: collapse; width: 100%; }&lt;br&gt;
    th, td { border: 1px solid #ddd; padding: 8px; font-size: 12px; }&lt;br&gt;
    th { background: #f5f5f5; text-align: left; }&lt;br&gt;
  &amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&lt;br&gt;
    &amp;lt;h1&amp;gt;Orders Report&amp;lt;/h1&amp;gt;&lt;br&gt;
    &amp;lt;table&amp;gt;&lt;br&gt;
      &amp;lt;thead&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;order_id&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;customer&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;amount&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;date&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;paid&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/thead&amp;gt;&lt;br&gt;
      &amp;lt;tbody&amp;gt;${rows}&amp;lt;/tbody&amp;gt;&lt;br&gt;
    &amp;lt;/table&amp;gt;&lt;br&gt;
  &amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;const browser = await puppeteer.launch();&lt;br&gt;
  const page = await browser.newPage();&lt;br&gt;
  await page.setContent(html, { waitUntil: 'networkidle0' });&lt;br&gt;
  await page.pdf({ path: 'orders.pdf', format: 'A4', printBackground: true });&lt;br&gt;
  await browser.close();&lt;br&gt;
})();&lt;br&gt;
`&lt;br&gt;
CLI (CSV → HTML → PDF)&lt;br&gt;
CSV to HTML (csvkit): csvlook -H orders.csv | sed 's/|/&lt;/p&gt;
&lt;td&gt;/g' won’t yield clean HTML on its own; better: in2csv orders.csv &amp;gt;/dev/null confirms validity, then use a template approach below.

&lt;p&gt;Pragmatic path:&lt;/p&gt;

&lt;p&gt;Use a simple template that embeds a generated HTML table (from a script or pandas), then&lt;/p&gt;

&lt;p&gt;Convert with wkhtmltopdf: wkhtmltopdf report.html orders.pdf&lt;br&gt;
For complex PDFs (headers, footers, page numbers), prefer HTML+CSS → PDF engines over pure PDF libraries.&lt;/p&gt;

&lt;p&gt;CSV to HTML&lt;br&gt;
Perfect for dashboards, documentation, and web embeds.&lt;/p&gt;

&lt;p&gt;Approaches&lt;br&gt;
Pandas one-liner: Quick table for internal pages.&lt;/p&gt;

&lt;p&gt;Static site build: Use a template and inject table rows.&lt;/p&gt;

&lt;p&gt;Interactive table: Add sorting, filtering, pagination with a JS library.&lt;/p&gt;

&lt;p&gt;Examples&lt;br&gt;
Python (pandas → HTML table)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import pandas as pd&lt;br&gt;
df = pd.read_csv("orders.csv")&lt;br&gt;
html = df.to_html(index=False, classes="table table-sm", border=0)&lt;br&gt;
open("orders.html", "w").write(f"""&lt;br&gt;
&amp;lt;!doctype html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&lt;br&gt;
  &amp;lt;meta charset="utf-8"&amp;gt;&lt;br&gt;
  &amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&lt;br&gt;
  &amp;lt;h1&amp;gt;Orders&amp;lt;/h1&amp;gt;&lt;br&gt;
  {html}&lt;br&gt;
&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;br&gt;
""")&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Vanilla HTML + Papa Parse (client-side)&lt;br&gt;
&lt;code&gt;&amp;lt;!doctype html&amp;gt;&lt;br&gt;
&amp;lt;html&amp;gt;&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
  &amp;lt;meta charset="utf-8" /&amp;gt;&lt;br&gt;
  &amp;lt;title&amp;gt;Orders&amp;lt;/title&amp;gt;&lt;br&gt;
  &amp;lt;script src="https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;
  &amp;lt;style&amp;gt;&lt;br&gt;
    table { border-collapse: collapse; width: 100%; }&lt;br&gt;
    th, td { border: 1px solid #ddd; padding: 8px; font-size: 12px; }&lt;br&gt;
    th { background: #f5f5f5; text-align: left; }&lt;br&gt;
  &amp;lt;/style&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
  &amp;lt;h1&amp;gt;Orders&amp;lt;/h1&amp;gt;&lt;br&gt;
  &amp;lt;table id="tbl"&amp;gt;&amp;lt;thead&amp;gt;&amp;lt;/thead&amp;gt;&amp;lt;tbody&amp;gt;&amp;lt;/tbody&amp;gt;&amp;lt;/table&amp;gt;&lt;br&gt;
  &amp;lt;script&amp;gt;&lt;br&gt;
    Papa.parse('orders.csv', {&lt;br&gt;
      download: true, header: true, dynamicTyping: true,&lt;br&gt;
      complete: ({ data, meta }) =&amp;gt; {&lt;br&gt;
        const thead = document.querySelector('#tbl thead');&lt;br&gt;
        const tbody = document.querySelector('#tbl tbody');&lt;br&gt;
        thead.innerHTML = '&amp;lt;tr&amp;gt;' + meta.fields.map(h =&amp;gt;&lt;/code&gt;&lt;/p&gt;


&lt;/td&gt;
&lt;th&gt;${h}&lt;/th&gt;
&lt;code&gt;).join('') + '&amp;lt;/tr&amp;gt;';&lt;br&gt;&lt;br&gt;
        tbody.innerHTML = data.map(r =&amp;gt;&lt;br&gt;&lt;br&gt;
          '&amp;lt;tr&amp;gt;' + meta.fields.map(h =&amp;gt;&lt;/code&gt;&lt;td&gt;${r[h] ?? ''}&lt;/td&gt;
&lt;code&gt;).join('') + '&amp;lt;/tr&amp;gt;'&lt;br&gt;&lt;br&gt;
        ).join('');&lt;br&gt;&lt;br&gt;
      }&lt;br&gt;&lt;br&gt;
    });&lt;br&gt;&lt;br&gt;
  &amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;br&gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Tuesday&lt;br&gt;&lt;br&gt;
write a detailed post on CSV to PDF, HTML, JSON and SQL converters. Pleae quote some examples too.

&lt;p&gt;Converting CSV to PDF, HTML, JSON, and SQL&lt;/p&gt;

&lt;p&gt;CSV is simple, portable, and everywhere—but raw grids rarely tell the story on their own.&lt;a href="https://thefreeconverter.com/converters/csv-converters" rel="noopener noreferrer"&gt; Converting CSV into richer formats&lt;/a&gt; helps you present, publish, integrate, or load data into apps and databases. Below is a practical, example‑driven guide you can use right away.&lt;/p&gt;

&lt;p&gt;Starter dataset used in examples&lt;br&gt;
Here’s a tiny CSV we’ll convert in multiple ways:&lt;/p&gt;

&lt;p&gt;order_id,customer,amount,date,paid&lt;br&gt;
1001,Asha,49.99,2025-07-31,true&lt;br&gt;
1002,Omar,125.00,2025-08-01,false&lt;br&gt;
1003,Meera,75.50,2025-08-01,true&lt;br&gt;
CSV to PDF&lt;br&gt;
Use this when you need a polished, shareable report: invoices, statements, dashboards.&lt;/p&gt;

&lt;p&gt;Approaches&lt;br&gt;
Direct table rendering: Quick export of a table with minimal styling.&lt;/p&gt;

&lt;p&gt;HTML-to-PDF pipeline: Generate an HTML report (with CSS) then print to PDF for pixel‑perfect control.&lt;/p&gt;

&lt;p&gt;Programmatic report layouts: Build page headers/footers, pagination, totals, and charts in code.&lt;/p&gt;

&lt;p&gt;Examples&lt;br&gt;
Python (pandas + WeasyPrint)&lt;br&gt;
python&lt;br&gt;
import pandas as pd&lt;br&gt;
from weasyprint import HTML, CSS&lt;/p&gt;

&lt;p&gt;df = pd.read_csv("orders.csv")&lt;br&gt;
html = f"""&lt;br&gt;
&amp;lt;!doctype html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;br&gt;
  &lt;br&gt;
  &amp;lt;br&amp;gt;
    body {{ font-family: Arial, sans-serif; margin: 24px; }}&amp;lt;br&amp;gt;
    h1 {{ margin-bottom: 8px; }}&amp;lt;br&amp;gt;
    table {{ border-collapse: collapse; width: 100%; }}&amp;lt;br&amp;gt;
    th, td {{ border: 1px solid #ddd; padding: 8px; font-size: 12px; }}&amp;lt;br&amp;gt;
    th {{ background: #f5f5f5; text-align: left; }}&amp;lt;br&amp;gt;
    tfoot td {{ font-weight: bold; }}&amp;lt;br&amp;gt;
  &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;h1&gt;Orders Report&lt;/h1&gt;
&lt;br&gt;
  {df.to_html(index=False)}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
"""&lt;br&gt;
HTML(string=html).write_pdf("orders.pdf")&lt;br&gt;
What it does: Reads CSV, renders a styled HTML table, prints it to PDF.

&lt;p&gt;Why it’s nice: Full CSS support; easy to brand.&lt;/p&gt;

&lt;p&gt;Node.js (Puppeteer: HTML template → PDF)&lt;br&gt;
js&lt;br&gt;
const fs = require('fs');&lt;br&gt;
const Papa = require('papaparse');&lt;br&gt;
const puppeteer = require('puppeteer');&lt;/p&gt;

&lt;p&gt;(async () =&amp;gt; {&lt;br&gt;
  const csv = fs.readFileSync('orders.csv', 'utf8');&lt;br&gt;
  const { data } = Papa.parse(csv, { header: true, dynamicTyping: true });&lt;/p&gt;

&lt;p&gt;const rows = data.map(r =&amp;gt; &lt;code&gt;&lt;br&gt;
    &amp;lt;tr&amp;gt;&lt;br&gt;
      &amp;lt;td&amp;gt;${r.order_id}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;${r.customer}&amp;lt;/td&amp;gt;&lt;br&gt;
      &amp;lt;td&amp;gt;${r.amount}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;${r.date}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;${r.paid}&amp;lt;/td&amp;gt;&lt;br&gt;
    &amp;lt;/tr&amp;gt;&lt;/code&gt;).join('');&lt;/p&gt;

&lt;p&gt;const html = &lt;code&gt;&lt;br&gt;
  &amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;style&amp;gt;&lt;br&gt;
    body { font-family: Arial, sans-serif; margin: 24px; }&lt;br&gt;
    table { border-collapse: collapse; width: 100%; }&lt;br&gt;
    th, td { border: 1px solid #ddd; padding: 8px; font-size: 12px; }&lt;br&gt;
    th { background: #f5f5f5; text-align: left; }&lt;br&gt;
  &amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&lt;br&gt;
    &amp;lt;h1&amp;gt;Orders Report&amp;lt;/h1&amp;gt;&lt;br&gt;
    &amp;lt;table&amp;gt;&lt;br&gt;
      &amp;lt;thead&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;order_id&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;customer&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;amount&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;date&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;paid&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/thead&amp;gt;&lt;br&gt;
      &amp;lt;tbody&amp;gt;${rows}&amp;lt;/tbody&amp;gt;&lt;br&gt;
    &amp;lt;/table&amp;gt;&lt;br&gt;
  &amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;const browser = await puppeteer.launch();&lt;br&gt;
  const page = await browser.newPage();&lt;br&gt;
  await page.setContent(html, { waitUntil: 'networkidle0' });&lt;br&gt;
  await page.pdf({ path: 'orders.pdf', format: 'A4', printBackground: true });&lt;br&gt;
  await browser.close();&lt;br&gt;
})();&lt;br&gt;
CLI (CSV → HTML → PDF)&lt;br&gt;
CSV to HTML (csvkit): csvlook -H orders.csv | sed 's/|/&lt;/p&gt;
&lt;td&gt;/g' won’t yield clean HTML on its own; better: in2csv orders.csv &amp;gt;/dev/null confirms validity, then use a template approach below.

&lt;p&gt;Pragmatic path:&lt;/p&gt;

&lt;p&gt;Use a simple template that embeds a generated HTML table (from a script or pandas), then&lt;/p&gt;

&lt;p&gt;Convert with wkhtmltopdf: wkhtmltopdf report.html orders.pdf&lt;/p&gt;

&lt;p&gt;Tip: For complex PDFs (headers, footers, page numbers), prefer HTML+CSS → PDF engines over pure PDF libraries.&lt;/p&gt;

&lt;p&gt;CSV to HTML&lt;br&gt;
Perfect for dashboards, documentation, and web embeds.&lt;/p&gt;

&lt;p&gt;Approaches&lt;br&gt;
Pandas one-liner: Quick table for internal pages.&lt;/p&gt;

&lt;p&gt;Static site build: Use a template and inject table rows.&lt;/p&gt;

&lt;p&gt;Interactive table: Add sorting, filtering, pagination with a JS library.&lt;/p&gt;

&lt;p&gt;Examples&lt;br&gt;
Python (pandas → HTML table)&lt;br&gt;
python&lt;br&gt;
import pandas as pd&lt;br&gt;
df = pd.read_csv("orders.csv")&lt;br&gt;
html = df.to_html(index=False, classes="table table-sm", border=0)&lt;br&gt;
open("orders.html", "w").write(f"""&lt;br&gt;
&amp;lt;!doctype html&amp;gt;&lt;/p&gt;


&lt;h1&gt;Orders&lt;/h1&gt;
&lt;br&gt;
&lt;br&gt;&lt;br&gt;
  {html}&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
""")&lt;br&gt;&lt;br&gt;
Vanilla HTML + Papa Parse (client-side)&lt;br&gt;&lt;br&gt;
html&lt;br&gt;&lt;br&gt;
&amp;lt;!doctype html&amp;gt;&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  Orders&lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &amp;lt;br&amp;gt;&lt;br&gt;
    table { border-collapse: collapse; width: 100%; }&amp;lt;br&amp;gt;&lt;br&gt;
    th, td { border: 1px solid #ddd; padding: 8px; font-size: 12px; }&amp;lt;br&amp;gt;&lt;br&gt;
    th { background: #f5f5f5; text-align: left; }&amp;lt;br&amp;gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
  &lt;h1&gt;Orders&lt;/h1&gt;
&lt;br&gt;
&lt;br&gt;&lt;br&gt;
  &lt;div class="table-wrapper-paragraph"&gt;&lt;table id="tbl"&gt;
&lt;br&gt;
&lt;thead&gt;&lt;/thead&gt;
&lt;br&gt;
&lt;tbody&gt;&lt;/tbody&gt;
&lt;br&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;&lt;br&gt;
  &amp;lt;br&amp;gt;&lt;br&gt;
    Papa.parse(&amp;amp;#39;orders.csv&amp;amp;#39;, {&amp;lt;br&amp;gt;&lt;br&gt;
      download: true, header: true, dynamicTyping: true,&amp;lt;br&amp;gt;&lt;br&gt;
      complete: ({ data, meta }) =&amp;amp;gt; {&amp;lt;br&amp;gt;&lt;br&gt;
        const thead = document.querySelector(&amp;amp;#39;#tbl thead&amp;amp;#39;);&amp;lt;br&amp;gt;&lt;br&gt;
        const tbody = document.querySelector(&amp;amp;#39;#tbl tbody&amp;amp;#39;);&amp;lt;br&amp;gt;&lt;br&gt;
        thead.innerHTML = &amp;amp;#39;&amp;lt;tr&amp;gt;&amp;amp;#39; + meta.fields.map(h =&amp;amp;gt; &amp;lt;code&amp;gt;&amp;amp;lt;th&amp;amp;gt;${h}&amp;amp;lt;/th&amp;amp;gt;&amp;lt;/code&amp;gt;).join(&amp;amp;#39;&amp;amp;#39;) + &amp;amp;#39;&amp;lt;/tr&amp;gt;&amp;amp;#39;;&amp;lt;br&amp;gt;&lt;br&gt;
        tbody.innerHTML = data.map(r =&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;
          &amp;amp;#39;&amp;lt;tr&amp;gt;&amp;amp;#39; + meta.fields.map(h =&amp;amp;gt; &amp;lt;code&amp;gt;&amp;amp;lt;td&amp;amp;gt;${r[h] ?? &amp;amp;#39;&amp;amp;#39;}&amp;amp;lt;/td&amp;amp;gt;&amp;lt;/code&amp;gt;).join(&amp;amp;#39;&amp;amp;#39;) + &amp;amp;#39;&amp;lt;/tr&amp;gt;&amp;amp;#39;&amp;lt;br&amp;gt;&lt;br&gt;
        ).join(&amp;amp;#39;&amp;amp;#39;);&amp;lt;br&amp;gt;&lt;br&gt;
      }&amp;lt;br&amp;gt;&lt;br&gt;
    });&amp;lt;br&amp;gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
&lt;br&gt;

&lt;p&gt;CSV to JSON&lt;br&gt;
Use this to feed APIs, store config/state, or work with JavaScript apps.&lt;/p&gt;

&lt;p&gt;Mapping choices&lt;br&gt;
Flat array of objects: Each CSV row becomes one JSON object.&lt;/p&gt;

&lt;p&gt;Type inference: Convert numbers, booleans, and nulls—don’t keep everything as strings.&lt;/p&gt;

&lt;p&gt;Grouping/nesting: Build nested structures by grouping columns (e.g., address_* → address object).&lt;br&gt;
Examples&lt;br&gt;
Output (flat array)&lt;br&gt;
&lt;code&gt;[&lt;br&gt;
  {"order_id":1001,"customer":"Asha","amount":49.99,"date":"2025-07-31","paid":true},&lt;br&gt;
  {"order_id":1002,"customer":"Omar","amount":125.0,"date":"2025-08-01","paid":false},&lt;br&gt;
  {"order_id":1003,"customer":"Meera","amount":75.5,"date":"2025-08-01","paid":true}&lt;br&gt;
]&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Python (pandas)&lt;br&gt;
&lt;code&gt;import pandas as pd&lt;br&gt;
df = pd.read_csv("orders.csv", true_values=["true"], false_values=["false"])&lt;br&gt;
df.to_json("orders.json", orient="records")&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Node (Papa Parse)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const fs = require('fs');&lt;br&gt;
const Papa = require('papaparse');&lt;br&gt;
const csv = fs.readFileSync('orders.csv', 'utf8');&lt;br&gt;
const { data } = Papa.parse(csv, { header: true, dynamicTyping: true });&lt;br&gt;
fs.writeFileSync('orders.json', JSON.stringify(data, null, 2));&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
If you need nested JSON, split column names on a delimiter (e.g., address.city) and build objects recursively.&lt;/p&gt;

&lt;p&gt;CSV to SQL&lt;br&gt;
Load into databases for analysis, joins, dashboards, or transactional apps.&lt;/p&gt;

&lt;p&gt;Mapping choices&lt;br&gt;
Schema inference: Guess column types (INTEGER, DECIMAL, DATE, BOOLEAN, TEXT).&lt;/p&gt;

&lt;p&gt;Identifiers: Sanitize column names to valid SQL identifiers.&lt;/p&gt;

&lt;p&gt;Loading path: INSERT statements vs. bulk COPY/LOAD for speed.&lt;/p&gt;

&lt;p&gt;Examples&lt;br&gt;
Inferred schema and inserts (SQLite syntax&lt;br&gt;
`CREATE TABLE orders (&lt;br&gt;
  order_id INTEGER,&lt;br&gt;
  customer TEXT,&lt;br&gt;
  amount REAL,&lt;br&gt;
  date TEXT,&lt;br&gt;
  paid BOOLEAN&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;INSERT INTO orders (order_id, customer, amount, date, paid) VALUES&lt;br&gt;
(1001, 'Asha', 49.99, '2025-07-31', 1),&lt;br&gt;
(1002, 'Omar', 125.00, '2025-08-01', 0),&lt;br&gt;
(1003, 'Meera', 75.50, '2025-08-01', 1);&lt;br&gt;
&lt;code&gt;&lt;br&gt;
csvkit (CLI) — infer CREATE TABLE and SQL&lt;br&gt;
&lt;/code&gt;# Preview inferred schema as a CREATE TABLE statement&lt;br&gt;
csvsql --dialect sqlite --tables orders --no-create --insert orders.csv &amp;gt; inserts.sql&lt;/p&gt;

&lt;h1&gt;
  
  
  Or generate a CREATE TABLE statement
&lt;/h1&gt;

&lt;p&gt;csvsql --dialect sqlite --tables orders orders.csv &amp;gt; create_table.sql&lt;br&gt;
`&lt;br&gt;
PostgreSQL bulk load&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-- In psql shell:&lt;br&gt;
\copy orders(order_id, customer, amount, date, paid) FROM 'orders.csv' CSV HEADER;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Python (pandas → SQLAlchemy)&lt;/p&gt;

&lt;p&gt;`import pandas as pd&lt;br&gt;
from sqlalchemy import create_engine&lt;/p&gt;

&lt;p&gt;df = pd.read_csv("orders.csv", true_values=["true"], false_values=["false"])&lt;br&gt;
engine = create_engine("sqlite:///example.db")&lt;br&gt;
df.to_sql("orders", engine, if_exists="replace", index=False)&lt;br&gt;
`&lt;br&gt;
For very large CSVs, prefer bulk loaders (PostgreSQL COPY, MySQL LOAD DATA, SQL Server BULK INSERT) over INSERT loops&lt;/p&gt;


&lt;/td&gt;

</description>
      <category>json</category>
      <category>pdf</category>
      <category>sql</category>
      <category>csv</category>
    </item>
    <item>
      <title>How Self Storage Code Works At Backend? Practical Code Examples</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Thu, 14 Aug 2025 08:00:56 +0000</pubDate>
      <link>https://dev.to/danish/how-self-storage-code-works-at-backend-practical-code-examples-4cao</link>
      <guid>https://dev.to/danish/how-self-storage-code-works-at-backend-practical-code-examples-4cao</guid>
      <description>&lt;p&gt;Self storage as a business is very popular all over the world. However, many don't know how the software that runs its mechanism works at backend--especially when it's being used for self storage unit automation. &lt;/p&gt;

&lt;p&gt;In this post I have shown the self storage code examples with that we will explore how these snippets actually power the tenant experience in a self storage unit which is cloud based. Think of it as watching the gears turn behind the scenes at a modern facility: clean, quick, and designed to make people’s lives easier.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Tenant Login - Behind Every Door Is a Story&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
When a tenant walks into a storage facility—or logs into their portal from the comfort of their couch—they expect simplicity. They’re not tech experts, they just want to check their payment history, renew their lease, or maybe update their auto-pay settings. That’s where the login system becomes more than just a gatekeeper; it becomes their digital concierge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python
from flask_login import LoginManager, UserMixin

class User(UserMixin):
    def __init__(self, user_id, role):
        self.id = user_id
        self.role = role  # 'admin', 'manager', 'tenant'

def check_access(user):
    if user.role == 'admin':
        return "Full access granted"
    elif user.role == 'manager':
        return "Unit management allowed"
    elif user.role == 'tenant':
        return "Lease view + Payment portal"
    else:
        return "Access denied"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet shows a login system that’s quietly powerful. A tenant logs in, and the software instantly knows who they are, what they should see, and what they’re allowed to do. Managers see operational dashboards; tenants get lease documents and payment tools. It’s intuitive, role-based, and makes the software feel tailored—not generic.&lt;/p&gt;

&lt;p&gt;At one facility I visited in Rawalpindi, the manager said her favorite moment was watching an elderly tenant successfully access his lease terms from a tablet his grandson set up. No frantic phone calls. No staff intervention. Just “click, click, done.”&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Billing That Feels Thoughtful—Not Mechanical&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Reminders aren't just about automation; they’re about respect. You wouldn’t want your tenants to feel ambushed by late fees or confused by billing gaps, and thankfully, with code like this, reminders become routine—but also kind and timely.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python
import schedule
import time
from datetime import datetime

def send_payment_reminder(tenant_email):
    print(f"Reminder sent to {tenant_email} on {datetime.now()}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;`# Every morning at 9 AM&lt;br&gt;
schedule.every().day.at("09:00").do(send_payment_reminder, tenant_email="&lt;a href="mailto:user@domain.com"&gt;user@domain.com&lt;/a&gt;")&lt;/p&gt;

&lt;p&gt;while True:&lt;br&gt;
    schedule.run_pending()&lt;br&gt;
    time.sleep(60)`&lt;/p&gt;

&lt;p&gt;Instead of relying on sticky notes or flagged calendars, the system nudges tenants just before rent is due. One operator in Karachi told me he had tenants who said these reminders felt “like a helpful assistant who never sleeps.” That’s the goal here—make tenants feel supported, not watched.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Knowing What’s Occupied, Vacant, or Reserved—With One Look&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
You’d be surprised how often self-storage owners say, “I just need a quick glance to know what’s going on.” So we built just that. This dashboard logic provides instant clarity, no matter if you’re managing ten units or a thousand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const units = [
  {id: 101, status: "occupied"},
  {id: 102, status: "vacant"},
  {id: 103, status: "reserved"}
];

const getUnitSummary = (units) =&amp;gt; {
  let summary = {
    occupied: 0,
    vacant: 0,
    reserved: 0
  };

  units.forEach(unit =&amp;gt; summary[unit.status]++);
  return summary;
};

console.log(getUnitSummary(units));
// Output: { occupied: 1, vacant: 1, reserved: 1 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s a snapshot of your entire facility. And it’s not just for owners—the front-desk team uses it to suggest units to walk-ins. A manager in Hyderabad once joked that before this dashboard, she had to “play Sudoku with a whiteboard” to track reservations. Now? It’s handled in milliseconds.&lt;/p&gt;

&lt;p&gt;The takeaway is this--- &lt;a href="https://smartstoragesoftware.com/the-evolution-of-self-storage-software-which-solution-powers-the-future-of-operations/" rel="noopener noreferrer"&gt;cloud-based storage software&lt;/a&gt; isn’t just smarter—it’s more personal. It turns tech into trust, and code into comfort. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>selfstorageunit</category>
      <category>propertymanagementcode</category>
    </item>
    <item>
      <title>Why Smart Storage Software Is a Game-Changer for Self Storage Operators in 2025</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Thu, 12 Jun 2025 15:10:53 +0000</pubDate>
      <link>https://dev.to/danish/why-smart-storage-software-is-a-game-changer-for-self-storage-operators-in-2025-26i4</link>
      <guid>https://dev.to/danish/why-smart-storage-software-is-a-game-changer-for-self-storage-operators-in-2025-26i4</guid>
      <description>&lt;p&gt;If you have ever managed more than one self storage facility, you know how quickly things can get complicated. I remember when I first took on managing multiple locations — juggling different logins, trying to keep track of who rented what where, and constantly chasing down payments felt like spinning plates. That’s why when I discovered &lt;a href="https://smartstoragesoftware.com/" rel="noopener noreferrer"&gt;Smart Storage Software&lt;/a&gt;, it felt like a breath of fresh air. This isn’t just another piece of software; it’s like having a smart, reliable assistant who keeps everything running smoothly behind the scenes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;One of the first things that blew me away was how Smart Storage Software lets you control multiple locations from a single dashboard. Imagine being able to log in once and see the occupancy rates, revenue numbers, and customer activity for all your facilities at a glance. &lt;br&gt;
No more switching between different systems or trying to piece together reports from separate sources. I’ve used other popular platforms like 6Storage and Easy Storage Solutions, and while they offer multi-site management, Smart Storage’s interface is just cleaner and more intuitive. It’s like the difference between a cluttered desk and a neatly organized workspace — everything you need is right there, easy to find and understand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Security has always been a big concern for me, and Smart Storage’s integrated access control really puts my mind at ease. With real-time monitoring and gate controller integration, I can instantly grant or revoke access if needed, and get alerts if something unusual happens. It’s not just about locking gates; it’s about knowing you are providing a secure environment for your tenants’ belongings. I’ve tried other software like SiteLink and Innago, which have access control features, but Smart Storage’s tight integration with the hardware and live monitoring feels like having a security guard on duty 24/7 — without the extra payroll.&lt;/p&gt;

&lt;p&gt;Running a self storage business is all about steady cash flow, and Smart Storage’s automated revenue tools have saved me countless headaches. The software handles rate adjustments, recurring payments, and late fees automatically. Before, I used to spend hours each month manually updating rates and reminding tenants about late payments. Now, it’s all done behind the scenes, and I get clear reports showing exactly where my revenue stands. StoragePug and Easy Storage Solutions offer similar features, but Smart Storage’s customization options make it easier to tailor the automation to my specific business needs. It’s like having a financial assistant who never sleeps.&lt;/p&gt;

&lt;p&gt;Communication with tenants used to be a juggling act — emails, phone calls, texts, and sometimes no response at all. Smart Storage Software’s unlimited email messaging and integrated Twilio text messaging changed the game. Since 98% of texts get read, I rely heavily on text reminders for payments and gate codes. Plus, the software notifies my team when messages come in or go out, so nothing slips through the cracks. I’ve used StoragePug and Innago for messaging, but Smart Storage’s unlimited messaging and Twilio integration make sure I’m always connected with my renters, no matter how busy things get.&lt;/p&gt;

&lt;p&gt;One feature that’s been a lifesaver is how Smart Storage tracks customers who rent across multiple locations. Instead of creating separate accounts for each rental, tenants have one account showing all their units. This not only simplifies things for them but also makes managing accounts so much easier on my end. And the zero login payment link? Brilliant. Tenants can pay without needing to remember passwords, which has cut down my phone time by about 30%. I’ve seen Easy Storage Solutions and CCStorage offer good portals, but this password-free payment system is a real standout — it’s simple, secure, and convenient.&lt;/p&gt;

&lt;p&gt;Another bonus is the free website that comes with every subscription. In today’s digital world, having a professional, mobile-friendly website is non-negotiable. The site is optimized to help potential renters find you online without extra cost or hassle. StoragePug is known for their website features, but including this at every subscription level with Smart Storage Software means even smaller operators can compete online without breaking the bank.&lt;/p&gt;

&lt;p&gt;When it comes to understanding how your business is doing, Smart Storage’s reporting dashboard is a breath of fresh air. It pulls together everything — revenue, occupancy, communication logs — into clear, real-time reports. I’ve always appreciated SiteLink’s reporting, but Smart Storage’s dashboard is easier to navigate and doesn’t overwhelm you with data. It’s the kind of tool that helps you spot trends early and make smarter decisions before problems grow.&lt;/p&gt;

&lt;p&gt;Automation doesn’t stop at billing and payments. Smart Storage also automates your communication workflows, sending rent reminders, promotions, or policy updates without you lifting a finger. This has saved me from the monthly “heartburn” of manual outreach. While 6Storage offers similar automation, Smart Storage’s unlimited messaging and customization options let me keep a personal touch with my tenants — which is key in this business.&lt;/p&gt;

&lt;p&gt;If you are looking for some real-world tips based on my experience with Smart Storage Software, here’s what I’ve learned: Always keep your units organized and easy to access — invest in good shelving and clear labeling. Don’t cram units too full; it causes damage and frustrates tenants. Use your software’s customer tracking to identify tenants renting multiple units or locations and offer them personalized deals or upgrades. Automate your communication but don’t overdo it — tenants appreciate reminders, not spam. And finally, regularly review your reports to catch occupancy dips or revenue changes early so you can act fast.&lt;/p&gt;

&lt;p&gt;In the end, Smart Storage Software isn’t just another tool; it’s a partner that helps you run your business smarter, not harder. Compared to other popular options like Easy Storage Solutions, 6Storage, SiteLink, and StoragePug, it offers a unique blend of powerful automation, integrated security, and user-friendly communication that makes managing self storage easier and more profitable. If you are serious about growing your business in 2025, this software deserves a close look — it might just change the way you manage your facilities for the better.&lt;/p&gt;

</description>
      <category>cloudbasedstoragesoftware</category>
      <category>smartstoragesoftware</category>
      <category>storageunitsoftware</category>
      <category>selfstorageunitsoftware</category>
    </item>
    <item>
      <title>Top 5 Features of React v19 You Need to Know</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Thu, 19 Dec 2024 10:26:04 +0000</pubDate>
      <link>https://dev.to/danish/top-5-features-of-react-v19-you-need-to-know-5egf</link>
      <guid>https://dev.to/danish/top-5-features-of-react-v19-you-need-to-know-5egf</guid>
      <description>&lt;p&gt;We use React for building user interfaces, and we see it in 2025, it continues to evolve with each new version. The release of &lt;a href="https://react.dev/blog/2024/12/05/react-19" rel="noopener noreferrer"&gt;React v19&lt;/a&gt; introduces several exciting features designed to enhance performance, usability, and developer experience. This guide shows us five coolest features of &lt;a href="https://laramatic.com/react-v19-code-examples/" rel="noopener noreferrer"&gt;new React v19&lt;/a&gt;, including the new React Compiler, Server Components, Actions, Enhanced Hooks, and improved Asset Loading that I have explained below in great detail. These features offer significant improvements that can help developers create more efficient, responsive, and maintainable applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  ** 5 Cool Features of New React v19
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;h2&gt;
  
  
  #1 React Compiler
&lt;/h2&gt;

&lt;p&gt;The React Compiler is a standout feature of React v19. It transforms your React code into optimized JavaScript, boosting performance and eliminating the need for manual optimizations like useMemo or useCallback. This means cleaner code and better performance without the extra effort. The compiler handles these optimizations automatically, resulting in more efficient and maintainable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  #2 Server Components
&lt;/h2&gt;

&lt;p&gt;React v19 introduces Server Components, which handle rendering on the server before sending the final page to the client. This can significantly improve load times and reduce the amount of code running on the client side, making your applications faster and more efficient. Server Components are particularly useful for large-scale applications where performance is critical, as they allow for complex computations to be handled server-side.&lt;/p&gt;

&lt;h2&gt;
  
  
  #3 Actions
&lt;/h2&gt;

&lt;p&gt;Actions are a new way to handle interactions with DOM elements, such as form submissions. They simplify the process of managing form state and handling user inputs, making it easier to build interactive and responsive applications. For example, you can use Actions to streamline form handling, reducing boilerplate code and improving the overall user experience. This feature enhances the interactivity of applications by providing a more intuitive and flexible way to manage user interactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  #4 Enhanced Hooks
&lt;/h2&gt;

&lt;p&gt;React v19 introduces new hooks like useFormStatus, useFormState, and useOptimistic, which provide more powerful and flexible ways to manage state and handle user interactions. These hooks streamline common tasks and improve the overall development experience. For instance, useFormStatus can help you manage the status of a form, while useFormState can handle the state of form inputs more efficiently. These hooks enable developers to write cleaner and more concise code, making it easier to build and maintain complex applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  #5 Asset Loading
&lt;/h2&gt;

&lt;p&gt;React v19 improves asset loading by enabling assets to load in the background, which enhances the application's load time and user experience. This feature ensures that your application remains responsive and fast, even when dealing with large assets. For example, images and other media files can load seamlessly without causing delays in the user interface. This improvement helps maintain a smooth and uninterrupted user experience, especially in media-rich applications.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>coding</category>
      <category>react</category>
    </item>
    <item>
      <title>5 MOST Important JS Concepts To Master JavaScript</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Fri, 29 Nov 2024 08:01:41 +0000</pubDate>
      <link>https://dev.to/danish/5-most-important-js-concepts-to-master-javascript-4pn1</link>
      <guid>https://dev.to/danish/5-most-important-js-concepts-to-master-javascript-4pn1</guid>
      <description>&lt;p&gt;JavaScript is a versatile and powerful language that's essential for modern web development. To become proficient in JavaScript, it's crucial to understand some of its core concepts. These concepts not only help in writing efficient and maintainable code but also enable developers to build complex and dynamic web applications. In this guide, we will explore five cool JavaScript concepts that every developer should know about: Scope and Closures, Asynchronous Programming with Promises and Async/Await, Event Loop and Callbacks, Higher-Order Functions and Functional Programming, and Prototypal Inheritance. By mastering these concepts, you would be gaining a deeper understanding of JavaScript and enhance your coding skills significantly. Let's read-below and discover the intricacies of these fascinating topics!&lt;br&gt;
These Are The 5 Cool JavaScript Concepts THAT Every Developer Should Know About:&lt;/p&gt;

&lt;h2&gt;
  
  
  1 – Scope &amp;amp; Closures
&lt;/h2&gt;

&lt;p&gt;Understanding scope is crucial in JavaScript. Scope determines the accessibility of variables, functions, and objects in your code. There are two main types of scope: global scope and local (or function) scope. A variable declared outside of any function has a global scope, while a variable declared inside a function has a local scope. Closures are functions that remember and access variables from their outer scope even after the outer function has finished executing. This allows for powerful patterns like data encapsulation and function factories.&lt;/p&gt;

&lt;h2&gt;
  
  
  #2– Asynchronous Programming with Promises &amp;amp; Async/Await
&lt;/h2&gt;

&lt;p&gt;JavaScript is single-threaded, which means it can only execute one operation at a time. Asynchronous programming allows JavaScript to perform long-running tasks (like fetching data from an API) without blocking the main thread. Promises are objects representing the eventual completion or failure of an asynchronous operation. The async and await keywords make working with promises more straightforward by allowing you to write asynchronous code that looks synchronous.&lt;/p&gt;

&lt;h2&gt;
  
  
  #3– Event Loop &amp;amp; Callbacks
&lt;/h2&gt;

&lt;p&gt;The event loop is a fundamental part of JavaScript's concurrency model. It continuously checks the call stack and the task queue, executing functions from the call stack and adding functions from the task queue when the call stack is empty. Callbacks are functions passed into other functions as arguments, which are then invoked inside the outer function. Understanding the event loop and how callbacks work is essential for writing efficient and non-blocking code.&lt;/p&gt;

&lt;h3&gt;
  
  
  4– Higher-Order Functions &amp;amp; Functional Programming
&lt;/h3&gt;

&lt;p&gt;Higher-order functions are functions that take other functions as arguments or return functions as their results. They are a cornerstone of functional programming, a paradigm that emphasizes the use of pure functions and immutable data. Examples of higher-order functions include map, filter, and reduce, which are used to process arrays in a declarative way.&lt;/p&gt;

&lt;h2&gt;
  
  
  #5– Prototypal Inheritance
&lt;/h2&gt;

&lt;p&gt;JavaScript uses prototypal inheritance, which is different from classical inheritance used in languages like Java and C++. In prototypal inheritance, objects inherit directly from other objects. Every object has a prototype from which it can inherit properties and methods. This allows for flexible and dynamic code structures, but it can also be tricky to understand and manage.&lt;/p&gt;

&lt;p&gt;By mastering these &lt;a href="https://laramatic.com/tutorial-about-javascript-concepts-with-code-examples/" rel="noopener noreferrer"&gt;5 JavaScript concepts&lt;/a&gt;, you certainly would GET a deeper understanding of JavaScript and be better equipped to write efficient, maintainable, and powerful code. Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The Importance &amp; Uses of Telegram Channels/Group Links for Jobs, Education, &amp; Awareness</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Wed, 06 Nov 2024 05:34:12 +0000</pubDate>
      <link>https://dev.to/danish/the-importance-uses-of-telegram-channelsgroup-links-for-jobs-education-awareness-2o3k</link>
      <guid>https://dev.to/danish/the-importance-uses-of-telegram-channelsgroup-links-for-jobs-education-awareness-2o3k</guid>
      <description>&lt;p&gt;In recent years, Telegram channels have become one of the most effective ways to broadcast information to large audiences. Unlike one-on-one messaging, channels allow a single user or a group of administrators to send messages to an unlimited number of subscribers. These channels are used by various organizations, educators, job seekers, and awareness campaigns to share valuable information quickly and efficiently. Telegram channels are especially significant in areas like job searching, education, and spreading awareness due to their accessibility, immediacy, and ability to reach a global audience.&lt;/p&gt;

&lt;p&gt;This guide explores the importance and practical uses of Telegram channels in jobs, education, and awareness campaigns, explaining how this platform can be leveraged to maximize its potential.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Importance of Telegram Channels
&lt;/h2&gt;

&lt;p&gt;a. Wide Reach and Accessibility&lt;/p&gt;

&lt;p&gt;Telegram channels can support an unlimited number of subscribers, which makes them a powerful tool for reaching a broad audience. Unlike other social media platforms or messaging apps that may limit the number of participants or connections you can have, Telegram channels allow you to send information to millions of users at once. This scalability is crucial for large organizations, educators, and job portals looking to reach people globally or regionally.&lt;/p&gt;

&lt;p&gt;Besides, Telegram groups are easily accessible across multiple devices, including smartphones, tablets, and desktops. The platform is available on both Android and iOS, and users can sync their accounts across devices. This multi-platform support ensures that people can receive updates at their convenience, regardless of the device they are using.&lt;/p&gt;

&lt;p&gt;b. Real-Time and Instant Updates&lt;/p&gt;

&lt;p&gt;One of the key advantages of Telegram channels is the ability to send real-time notifications. When administrators post messages, subscribers receive them almost instantly. This is highly valuable in fields like job searching and education, where timeliness is critical. For instance, job seekers can be notified about a new job listing the moment it becomes available, giving them a competitive edge in applying quickly.&lt;/p&gt;

&lt;p&gt;Educational institutions can also use this feature to update students on important announcements, like changes to exam schedules, deadlines for assignments, or availability of study materials. Real-time updates ensure that everyone is informed promptly, which is essential for smooth communication and planning.&lt;/p&gt;

&lt;p&gt;c. Cost-Effective Communication&lt;/p&gt;

&lt;p&gt;Telegram channels are free to create and manage, making them an incredibly cost-effective communication tool for individuals and organizations. There are no fees for creating or subscribing to a channel, which is particularly advantageous for non-profits, educational institutions, and small businesses that may have limited budgets for communication and marketing.&lt;/p&gt;

&lt;p&gt;Organizations that might have otherwise spent significant amounts on email marketing campaigns, SMS notifications, or paid social media ads can leverage Telegram’s free channels to distribute the same information at no cost. This makes it a viable option for anyone seeking an affordable way to communicate with large audiences.&lt;/p&gt;

&lt;p&gt;d. Security and Privacy&lt;/p&gt;

&lt;p&gt;Telegram is known for its focus on security and privacy, offering end-to-end encryption for chats and privacy settings that protect user data. While the messages in channels are not end-to-end encrypted (as they are intended for broadcasting), Telegram still offers various privacy features that safeguard both administrators and subscribers. For example, subscribers to a channel do not have to reveal personal information like their phone numbers or email addresses to the channel admins, ensuring their privacy.&lt;/p&gt;

&lt;p&gt;Furthermore, administrators have complete control over the content that is shared, and only they can post messages. This one-way communication ensures that channels remain organized and free from spam, as only verified and relevant information is broadcast to the subscribers.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Uses of Telegram Channels for Jobs
&lt;/h2&gt;

&lt;p&gt;a. Job Listings and Recruitment Notifications&lt;/p&gt;

&lt;p&gt;One of the most common uses of Telegram channels is for posting job openings. Channels dedicated to specific industries or regions can regularly post new job listings, internships, or freelance opportunities. This provides job seekers with a centralized platform where they can browse opportunities from various companies or recruiters.&lt;/p&gt;

&lt;p&gt;For example, many recruitment agencies or job boards create Telegram channels where they post daily updates on new job openings. These channels are often categorized by job type, such as engineering, IT, marketing, or customer service, allowing subscribers to follow the channels most relevant to their career path. Job seekers can stay updated on the latest job opportunities without constantly checking multiple websites or apps.&lt;/p&gt;

&lt;p&gt;b. Career Guidance and Preparation Resources&lt;/p&gt;

&lt;p&gt;In addition to job postings, many Telegram channels offer career advice, resume tips, interview preparation guides, and insights into industry trends. These channels can help job seekers improve their employability by providing them with the resources they need to stand out in the job market.&lt;/p&gt;

&lt;p&gt;For instance, a channel might share posts about how to write a compelling resume, how to prepare for technical interviews, or how to network effectively within a particular industry. Some channels also invite industry experts to provide guidance through written posts, video interviews, or live Q&amp;amp;A sessions. This added value makes Telegram channels more than just job boards; they become a holistic resource for career development.&lt;/p&gt;

&lt;p&gt;c. Freelancing and Gig Economy Opportunities&lt;/p&gt;

&lt;p&gt;With the rise of the gig economy, Telegram channels have become an essential resource for freelancers looking for project-based work. Channels focused on freelance projects share short-term gigs or remote work opportunities that appeal to individuals seeking flexible work arrangements. These channels cater to various fields, including writing, graphic design, web development, and digital marketing.&lt;/p&gt;

&lt;p&gt;For example, a freelance writer can join channels that post writing gigs from clients all over the world. Freelancers can apply directly to the postings and often secure work without the need for an intermediary platform, streamlining the process and allowing for quick transactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Uses of Telegram Channels for Education
&lt;/h2&gt;

&lt;p&gt;a. Dissemination of Learning Materials and Resources&lt;/p&gt;

&lt;p&gt;Of all social media platforms, Telegram has a great way to connect people and these groups are widely used in the educational sector for sharing learning materials, such as PDFs, e-books, lecture notes, and video lessons. Educators and institutions can create channels where they post course content, exam schedules, and reading lists. This approach makes it easier for students to access study materials in one place.&lt;/p&gt;

&lt;p&gt;For instance, a university might create separate channels for each department or class, where professors upload reading materials, assignment details, and important announcements. This system ensures that students have immediate access to the resources they need, and they can refer back to previous posts as a study aid.&lt;/p&gt;

&lt;p&gt;b. Conducting Interactive Quizzes and Polls&lt;/p&gt;

&lt;p&gt;Telegram channels include built-in tools like quizzes and polls, which educators can use to engage students and assess their learning. For example, after a lecture or a module, a teacher can post a quiz to test students’ understanding of the material. These quizzes can be set up with multiple-choice questions, and students can receive immediate feedback on their answers.&lt;/p&gt;

&lt;p&gt;Polls can also be used for gauging student opinions or preferences on various topics, such as choosing project topics or scheduling discussions. This interactive approach helps make learning more engaging and allows educators to measure the effectiveness of their teaching.&lt;/p&gt;

&lt;p&gt;c. Language Learning and Skill Development&lt;/p&gt;

&lt;p&gt;Many Telegram channels are dedicated to specific skill development areas, such as language learning, programming, or art. These channels offer a structured approach to learning, where subscribers receive daily lessons, exercises, and challenges to improve their skills gradually.&lt;/p&gt;

&lt;p&gt;For instance, a channel dedicated to learning Spanish might post daily vocabulary lessons, grammar explanations, and pronunciation tips. Users can practice at their own pace, and the content is always available for reference. Similarly, a coding channel might offer daily challenges to help programmers improve their skills, such as algorithm problems or debugging exercises.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Uses of Telegram Channels for Awareness Campaigns
&lt;/h2&gt;

&lt;p&gt;a. Public Awareness and Social Advocacy&lt;/p&gt;

&lt;p&gt;Telegram channels are frequently used by NGOs, advocacy groups, and activists to raise awareness about social issues, health, environmental concerns, and human rights. These channels serve as a platform for spreading important information to a broad audience, often in regions where traditional media is restricted.&lt;/p&gt;

&lt;p&gt;For example, a health-focused channel might share information about the importance of vaccination, mental health resources, or updates on public health initiatives. Similarly, an environmental advocacy group might use Telegram channels to spread awareness about climate change, pollution, and conservation efforts.&lt;/p&gt;

&lt;p&gt;b. Civic Engagement and Political Awareness&lt;/p&gt;

&lt;p&gt;During elections or political movements, Telegram channels become crucial tools for disseminating information related to civic participation. Governments, political parties, and activists can use these channels to inform voters about election procedures, political events, and the importance of participating in democratic processes.&lt;/p&gt;

&lt;p&gt;In regions where media censorship is prevalent, Telegram channels also allow citizens to share uncensored news and coordinate peaceful protests. This use of Telegram channels ensures that important political messages reach a wide audience, even under restrictive conditions.&lt;/p&gt;

&lt;p&gt;c. Emergency Alerts and Crisis Communication&lt;/p&gt;

&lt;p&gt;During natural disasters, public health emergencies, or other crises, Telegram channels are often used to send emergency alerts and safety updates to communities. Government agencies and local authorities can post evacuation routes, shelter locations, and real-time updates on weather conditions or road closures. &lt;/p&gt;

&lt;p&gt;For example, during a hurricane, a city government might use a Telegram channel to share real-time updates about flooding, power outages, and emergency contact information. This instant communication can be lifesaving, as it ensures that citizens receive critical information when they need it most.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://mobilephun.com/arab-world-telegram-group-links/" rel="noopener noreferrer"&gt;Telegram channel and group links&lt;/a&gt; are an incredibly powerful tool for communication in the digital age in 2025. Their ability to broadcast messages to a large, targeted audience instantly, combined with their cost-effectiveness, security, and ease of use, makes them an indispensable resource for organizations, educators, and job seekers alike. Whether used for finding jobs, disseminating educational content, or raising awareness about critical social issues, Telegram channels offer a versatile and accessible platform that can benefit individuals and communities globally.&lt;/p&gt;

&lt;p&gt;By leveraging Telegram’s features, individuals and organizations can stay informed, share knowledge, and mobilize efforts more effectively in today’s fast-paced digital world.&lt;/p&gt;

</description>
      <category>socialmedia</category>
      <category>telegram</category>
      <category>telegramchannels</category>
    </item>
    <item>
      <title>Free AI Powered MarkDown To HTML Converter Tool</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Tue, 15 Oct 2024 08:32:43 +0000</pubDate>
      <link>https://dev.to/danish/free-ai-powered-markdown-to-html-converter-tool-24ie</link>
      <guid>https://dev.to/danish/free-ai-powered-markdown-to-html-converter-tool-24ie</guid>
      <description>&lt;p&gt;Check out this free Markdown to HTML converter tool. It's good to get things done quickly. At the backend AI powers this tool to get the job done. &lt;br&gt;
There are plenty of things this &lt;a href="https://thefreeconverter.com/html-tools/markdown-to-html" rel="noopener noreferrer"&gt;Markdown to HTML converter&lt;/a&gt; tool could do. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>html</category>
      <category>markdown</category>
    </item>
    <item>
      <title>How To Run Cron Jobs in Laravel</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Sun, 22 Sep 2024 18:06:49 +0000</pubDate>
      <link>https://dev.to/danish/how-to-run-cron-jobs-in-laravel-38i4</link>
      <guid>https://dev.to/danish/how-to-run-cron-jobs-in-laravel-38i4</guid>
      <description>&lt;p&gt;In this tutorial I will show you how we can run cron jobs in Laravel, but on top of all we would keep things simple and easy for our students. We would go to explore how to set up and run these automated tasks right on your own computer while we are building our Laravel app. &lt;/p&gt;

&lt;p&gt;First off, what exactly is a cron job? Think of it as a personal assistant for your website - one that never sleeps and always shows up on time. It's a task that you schedule to run automatically at specific times. In Laravel, we use these to &lt;a href="https://laramatic.com/automating-tasks-with-laravel-scheduler-explainer-with-code-examples/" rel="noopener noreferrer"&gt;handle repetitive jobs&lt;/a&gt; that keep our application running smoothly.  &lt;/p&gt;

&lt;p&gt;Now, you might be wondering, "How do I get these cron jobs running on my own computer?" We are going to walk through this step-by-step, and by the end, you would be scheduling tasks like a pro.&lt;/p&gt;

&lt;p&gt;Let's start with the heart of Laravel's scheduling system - the &lt;code&gt;app/Console/Kernel.php&lt;/code&gt; file. This is where the magic happens. When you open this file, you would see a method called &lt;code&gt;schedule&lt;/code&gt;. This is your playground for setting up tasks. Here's what it might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Schedule&lt;/span&gt; &lt;span class="nv"&gt;$schedule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$schedule&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'emails:send'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;daily&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we would tell Laravel, "Hey, I want you to send emails every day." It's that simple! Laravel gives you tons of options for when to run your tasks. You could run them every hour, once a week, or even every five minutes if you wanted to.&lt;/p&gt;

&lt;p&gt;Now, here's where things get a bit tricky. On a real web server, there's a system that automatically runs these scheduled tasks. But on your own computer, we need to get a bit creative.&lt;/p&gt;

&lt;p&gt;Laravel gives us a handy command to run our scheduled tasks manually. You can type this into your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan schedule:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command is like saying, "Run all the tasks that are due right now." But let's be honest, you don't want to sit there typing this command over and over again, right?&lt;/p&gt;

&lt;p&gt;So, here's a neat trick. We can create a simple script that runs this command for us every minute. It's like having a tiny robot assistant on your computer. Here's what that script might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="k"&gt;do
    &lt;/span&gt;php /path/to/your/project/artisan schedule:run &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /dev/null 2&amp;gt;&amp;amp;1
    &lt;span class="nb"&gt;sleep &lt;/span&gt;60
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't let this scare you! It's just telling your computer to run the schedule:run command every 60 seconds. You would save this as a .sh file and run it in the background while you're working on your project.&lt;/p&gt;

&lt;p&gt;As you are testing your scheduled tasks, it's a good idea to add some logging. This way, you can see what's happening behind the scenes. It's like leaving a trail of breadcrumbs for yourself.&lt;/p&gt;

&lt;p&gt;Remember, this setup is great for when you have been building and testing your app on your own computer. When you're ready to launch your website for real, you'll need to set things up a bit differently on your web server.&lt;/p&gt;

&lt;p&gt;Laravel's creator, Taylor Otwell, once said, "Task scheduling is a crucial aspect of modern web development, allowing developers to automate repetitive tasks and improve the overall efficiency of their applications." He's absolutely right! By mastering scheduled tasks, you're taking a big step towards building more powerful and efficient web applications.&lt;/p&gt;

&lt;p&gt;So there you have it! You are now equipped to set up and run cron jobs on your own computer while building your Laravel app. It might seem a bit complex at first, but with practice, you'll find it becomes second nature. Keep experimenting, and before you know it, you'll be scheduling tasks like a seasoned pro!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>php</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What Happens When a Super Admin Disallows User Logins Due to an Error</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Tue, 17 Sep 2024 07:41:35 +0000</pubDate>
      <link>https://dev.to/danish/what-happens-when-a-super-admin-disallows-user-logins-due-to-an-error-2bng</link>
      <guid>https://dev.to/danish/what-happens-when-a-super-admin-disallows-user-logins-due-to-an-error-2bng</guid>
      <description>&lt;p&gt;Imagine you are a user of a web app, excitedly navigating to the login page to access your account and you enter the credentials, click the shiny "Log In" button, and wait with anticipation. But alas, instead of being greeted by your personalized dashboard, an ominous error message appears: "Sorry, the site administrator has temporarily disabled user logins due to a system error." As frustration sets in, you may wonder what could have caused this inconvenience. Behind the scenes, the super admin of the application has made the decision to &lt;a href="https://laramatic.com/how-use-middleware-implement-simple-super-admin-action-laravel-code-example/" rel="noopener noreferrer"&gt;disallow user logins&lt;/a&gt;. This drastic measure is usually taken when a critical error has been detected within the system.&lt;/p&gt;

&lt;p&gt;Perhaps there was a security breach that compromised user data, and the super admin wants to prevent further unauthorized access until the vulnerability is patched or maybe a recent deployment introduced a crippling bug that corrupts user sessions, leading to a cascade of errors throughout the application.&lt;/p&gt;

&lt;p&gt;In such situations, the super admin has the power to swiftly disable user logins to contain the issue and minimize its impact. This is typically accomplished by modifying a configuration setting in the application's backend. For example, in a Ruby on Rails app, the super admin might add the following line to the config/application.rb file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.allow_user_login = false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By setting allow_user_login to false, the application will reject all incoming login requests. The login controller would check this configuration value and respond with an appropriate error message when a user attempts to log in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class LoginController &amp;lt; ApplicationController
  def create
    if Rails.application.config.allow_user_login
      # Process login request
    else
      flash[:error] = "Sorry, the site administrator has temporarily disabled user logins due to a system error."
      redirect_to login_path
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We must get this point here that the security is a process, not a product. By quickly disabling user logins, the super admin is taking a proactive step in the security process to protect user data and maintain the integrity of the app. While it may be inconvenient for users in the short term, this decisive action allows the development team to thoroughly investigate the issue, implement necessary fixes, and restore normal functionality. Rest assured, the super admin is working diligently behind the scenes to resolve the problem and enable user logins as soon as it is safe to do so. In the meantime, as a user, the best course of action is to remain patient and keep an eye out for official communication from the application's support team. They will likely provide updates on the status of the issue and notify you when the login functionality has been restored. You can read the complete guide on &lt;a href="https://laramatic.com/how-use-middleware-implement-simple-super-admin-action-laravel-code-example/" rel="noopener noreferrer"&gt;implementing super admin in Laravel&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>laravel</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using SCSS And TailwindCSS in Laravel Projects Code Examples</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Mon, 16 Sep 2024 05:38:40 +0000</pubDate>
      <link>https://dev.to/danish/using-scss-and-tailwindcss-in-laravel-projects-code-examples-56a7</link>
      <guid>https://dev.to/danish/using-scss-and-tailwindcss-in-laravel-projects-code-examples-56a7</guid>
      <description>&lt;p&gt;Being in the coding field one often realises what works and what not and what could make a definite change despite being something new. Well in this small tutorial I would show you this simplest thing using SCSS TailwindCSS together for a myriad number of web apps.This powerful duo can significantly enhance your web development workflow and create more maintainable stylesheets.&lt;/p&gt;

&lt;p&gt;So a little intro before getting over started here. Well, the Tailwind CSS has been gaining popularity among developers due to its utility-first approach. When you are using Tailwind, you are essentially composing your designs directly in your markup. This method can lead to rapid development and consistency across your project. However, some developers find that they miss the organizational benefits and advanced features of preprocessors like SCSS. That is where the combination of &lt;a href="https://laramatic.com/how-to-use-tailwindcss-scss-vite-for-new-projects-in-laravel/" rel="noopener noreferrer"&gt;Tailwind and SCSS &lt;/a&gt;comes into play. By leveraging both technologies, you get the best of both worlds. You have been able to use Tailwind's utility classes for quick styling while still having access to SCSS's powerful features such as variables, mixins, and nesting.&lt;/p&gt;

&lt;p&gt;Let us look at a practical example. Suppose you were working on a large-scale project with multiple themes. You could use SCSS variables to define your color palette and then use those variables in your Tailwind configuration. Here is how that might look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="c1"&gt;// _variables.scss&lt;/span&gt;
&lt;span class="nv"&gt;$primary-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#3490dc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$secondary-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#ffed4a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$danger-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#e3342f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// tailwind.config.js&lt;/span&gt;
&lt;span class="nt"&gt;module&lt;/span&gt;&lt;span class="nc"&gt;.exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$primary-color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;secondary&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$secondary-color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;danger&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$danger-color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach allows you to maintain a single source of truth for your color definitions, making it easier to update and maintain your styles across the entire project.&lt;/p&gt;

&lt;p&gt;Another benefit of using &lt;a href="https://laramatic.com/install-use-tailwindcss-and-sass-in-laravel/" rel="noopener noreferrer"&gt;SCSS with Tailwind&lt;/a&gt; is the ability to create more complex, reusable components. While Tailwind encourages a utility-first approach, there are times when you might want to create a more traditional CSS component. SCSS's nesting capabilities make this process much more manageable.&lt;/p&gt;

&lt;p&gt;Consider a button component. You could create it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="nt"&gt;py-2&lt;/span&gt; &lt;span class="nt"&gt;px-4&lt;/span&gt; &lt;span class="nt"&gt;rounded&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;-primary&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="nt"&gt;bg-primary&lt;/span&gt; &lt;span class="nt"&gt;text-white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="nt"&gt;bg-primary-dark&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nt"&gt;-secondary&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="nt"&gt;bg-secondary&lt;/span&gt; &lt;span class="nt"&gt;text-gray-800&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="nt"&gt;bg-secondary-dark&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have used SCSS nesting to create variations of our button component while still leveraging Tailwind's utility classes through the &lt;code&gt;@apply&lt;/code&gt; directive.&lt;/p&gt;

&lt;p&gt;I have to mention that while this combination can be powerful, it is important to use it judiciously. Overusing SCSS features could potentially negate some of the benefits of Tailwind's utility-first approach. It is all about finding the right balance for your project.&lt;/p&gt;

&lt;p&gt;As we were discussing the benefits, I was reminded of a quote by Adam Wathan, the creator of Tailwind CSS. He once said, "The biggest benefit of using a utility-first CSS framework is that it allows you to build custom designs without writing CSS." While this is true, I would argue that adding SCSS to the mix allows for even greater flexibility and maintainability in large-scale projects.&lt;/p&gt;

&lt;p&gt;Well so the you have seen above their combination of Tailwind CSS and SCSS could provide devs with a robust toolset for web apps. You would have been able to leverage the rapid development and consistency of Tailwind while still having access to the powerful features of SCSS. This approach could lead to more maintainable and scalable stylesheets, especially in larger projects. As with any tool or technique, the key is to understand when and how to use it effectively in your specific context.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>php</category>
      <category>laravel</category>
    </item>
    <item>
      <title>How to Pass Data From Route to Controller and View in Laravel 11</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Wed, 21 Aug 2024 09:57:26 +0000</pubDate>
      <link>https://dev.to/danish/how-to-pass-data-from-route-to-controller-and-view-in-laravel-11-35ed</link>
      <guid>https://dev.to/danish/how-to-pass-data-from-route-to-controller-and-view-in-laravel-11-35ed</guid>
      <description>&lt;p&gt;Since the 2020 leading up to 2024, the development in Laravel has been a blessing for the devs across the globe. In this small code example we would walk you the path of passing data from a route to a controller and then to a view is a fundamental aspect of Laravel development in general and we see that much often. Laravel 11, as with its previous versions, provides an elegant and efficient way to manage this process. Understanding how to effectively pass data between these components is crucial for building dynamic and responsive web applications.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(I) Overview of Laravel Routing&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
In Laravel, routes COULD BE defined in the &lt;code&gt;routes/web.php&lt;/code&gt; file. A route typically consists of a URL path and a corresponding action, such as invoking a method on a controller and so on so forth etc. When a user accesses a particular URL, Laravel determines the appropriate route and executes the associated logic.&lt;/p&gt;

&lt;p&gt;Code Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/example'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;ExampleController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'show'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, when a user visits the &lt;code&gt;/example&lt;/code&gt; URL, the &lt;code&gt;show&lt;/code&gt; method of the &lt;code&gt;ExampleController&lt;/code&gt; is executed.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(II) Passing Data from Route to Controller&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
So, the example given below you could see we would pass data from a route to a controller, and then we would include route parameters in the URL and access these parameters within the controller method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/user/{id}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;UserController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'show'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;{id}&lt;/code&gt; is a route parameter. When a user visits &lt;code&gt;/user/1&lt;/code&gt;, the &lt;code&gt;id&lt;/code&gt; value &lt;code&gt;1&lt;/code&gt; is passed to the &lt;code&gt;show&lt;/code&gt; method of &lt;code&gt;UserController&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Controller Method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Fetch the user data using the ID&lt;/span&gt;
    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Return the view with the user data&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user.profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this method, the &lt;code&gt;id&lt;/code&gt; parameter has been used for fetching a user from our database. The retrieved user data is then passed to the view.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(III) Passing Data from Controller to View&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Once the data is handled within the controller, it is often necessary to pass this data to a view for rendering. Laravel provides several ways to pass data from a controller to a view.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(i) Passing Data Using &lt;code&gt;with()&lt;/code&gt; Method&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Passing data using with() method&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user.profile'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;(ii) Passing Data Using an Associative Array&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Passing data using an associative array&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user.profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;(iii) Passing Data Using the &lt;code&gt;compact()&lt;/code&gt; Function&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Passing data using the compact() function&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user.profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;compact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In all the above tiny code examples the methods were used, the &lt;code&gt;$user&lt;/code&gt; variable were meant to made available to the &lt;code&gt;user.profile&lt;/code&gt; view, where then that could be used to display the user's information.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(IV) Accessing Passed Data in the View&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
In the view, the data passed from the controller can be accessed using Blade syntax, which is Laravel's templating engine.&lt;/p&gt;

&lt;p&gt;Example of a Blade View:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;User Profile&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{{ $user-&amp;gt;name }}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Email: {{ $user-&amp;gt;email }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code example, the &lt;code&gt;$user&lt;/code&gt; variable is accessed within the Blade view, and the user's name and email are displayed.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(V) Passing Multiple Parameters&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
You can also pass multiple parameters from a route to a controller and then to a view.&lt;/p&gt;

&lt;p&gt;Route Code Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/post/{id}/comment/{commentId}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;PostController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'showComment'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Controller Method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;showComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$commentId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Comment&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$commentId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'post.comment'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;compact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'comment'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, both the &lt;code&gt;post&lt;/code&gt; and &lt;code&gt;comment&lt;/code&gt; data are passed to the &lt;code&gt;post.comment&lt;/code&gt; view.&lt;/p&gt;

&lt;p&gt;(VI) Here are some High Notes for Better Understanding&lt;/p&gt;

&lt;p&gt;(i)- Use Named Routes: Laravel allows you to define named routes, which makes it easier to generate URLs or redirects within your application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;(ii) - Validate Input: Always validate the data coming from route parameters before processing it in the controller. Laravel’s built-in validation features can help ensure that the data meets the required criteria.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(iii) - Keep Controllers Clean: Follow the Single Responsibility Principle by ensuring that controllers are focused on a specific task. Delegate complex logic to services or repositories when necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(iv) - Use Dependency Injection: When possible, use dependency injection in controllers to inject required services or models, making the code more testable and maintainable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Passing data from a route to a controller and then to a view is a straightforward process in &lt;a href="https://laramatic.com/" rel="noopener noreferrer"&gt;Laravel 11 tutorials&lt;/a&gt; you can see more code examples. By understanding the various methods available and adhering to best practices, you can ensure that your application remains clean, efficient, and maintainable. Leveraging these techniques will allow you to build robust and scalable applications that are easy to manage and extend.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>php</category>
      <category>codeexamples</category>
    </item>
    <item>
      <title>How &amp; When To Use Event Listeners in Laravel 11? Practical Code Examples</title>
      <dc:creator>Danish</dc:creator>
      <pubDate>Thu, 15 Aug 2024 19:50:13 +0000</pubDate>
      <link>https://dev.to/danish/how-when-to-use-event-listeners-in-laravel-11-practical-code-examples-29mn</link>
      <guid>https://dev.to/danish/how-when-to-use-event-listeners-in-laravel-11-practical-code-examples-29mn</guid>
      <description>&lt;p&gt;Laravel's event system is phenomenal when it comes to dealing with the complex data in our web apps as it is a cornerstone for building decoupled and absolutely complex apps. This guide tells extremely detailed points on implementation and utilization of event listening especially in 2024, providing a fresh perspective with the most expansive content and &lt;a href="https://laramatic.com/a-guide-on-how-when-to-use-event-listening-in-laravel-11-with-code-examples/" rel="noopener noreferrer"&gt;detailed code examples event listeners in Laravel 11&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(A) Understanding The Core Behind Events and Listeners&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
SO, LET'S BREAK THEM DOWN, the events in Laravel do representing specific occurrences inside an app. Listeners are the classes that would respond to all such app events. This pattern keeps promoting a separation of concerns and has been allowing for more modular and testable code.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;(B) Creating an Event&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Let us begin by creating an even a complex event for that we will be using the Artisan command to explain better we highly suggest you'd do that too&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:event OrderPlaced&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will be generating a new event class in the app/Events directory. Let us examine a more detailed event class&lt;/p&gt;

&lt;p&gt;`namespace App\Events;&lt;/p&gt;

&lt;p&gt;use App\Models\Order;&lt;br&gt;
use App\Models\User;&lt;br&gt;
use Illuminate\Foundation\Events\Dispatchable;&lt;br&gt;
use Illuminate\Queue\SerializesModels;&lt;br&gt;
use Illuminate\Broadcasting\InteractsWithSockets;&lt;br&gt;
use Illuminate\Broadcasting\PrivateChannel;&lt;br&gt;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;&lt;/p&gt;

&lt;p&gt;class OrderPlaced implements ShouldBroadcast&lt;br&gt;
{&lt;br&gt;
    use Dispatchable, InteractsWithSockets, SerializesModels;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public $order;
public $user;

/**
 * Create a new event instance.
 *
 * @param  \App\Models\Order  $order
 * @param  \App\Models\User  $user
 * @return void
 */
public function __construct(Order $order, User $user)
{
    $this-&amp;gt;order = $order;
    $this-&amp;gt;user = $user;
}

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('orders.'.$this-&amp;gt;user-&amp;gt;id);
}

/**
 * The event's broadcast name.
 *
 * @return string
 */
public function broadcastAs()
{
    return 'order.placed';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In this expanded example, we have been including both the Order and User models. The &lt;em&gt;SerializesModels&lt;/em&gt; trait has been ensuring that our Eloquent models are correctly serialized and deserialized when the event is passed to queued listeners. We have also implemented the &lt;em&gt;ShouldBroadcast&lt;/em&gt; interface and defined the &lt;em&gt;broadcastOn&lt;/em&gt; and &lt;em&gt;broadcastAs&lt;/em&gt; methods, allowing this event to be broadcasted to websockets for real-time updates.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Creating Multiple Listeners&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
For a single event, we might want multiple listeners. Let us create two listeners for our &lt;em&gt;OrderPlaced&lt;/em&gt; event to expand the example furthermore. I just want you guys to make sure you get the gist of everything. So, for that please see the code example below&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:listener SendOrderConfirmation --event=OrderPlaced&lt;br&gt;
php artisan make:listener UpdateInventory --event=OrderPlaced&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;SO now you'd understand that this command line would get us a couple of new listener classes in the app/Listeners directory of ours. Now the thing is, here below, we would examine the &lt;em&gt;SendOrderConfirmation&lt;/em&gt; listener and see how to it how it progresses further&lt;/p&gt;

&lt;p&gt;`namespace App\Listeners;&lt;/p&gt;

&lt;p&gt;use App\Events\OrderPlaced;&lt;br&gt;
use App\Mail\OrderConfirmation;&lt;br&gt;
use Illuminate\Contracts\Queue\ShouldQueue;&lt;br&gt;
use Illuminate\Queue\InteractsWithQueue;&lt;br&gt;
use Illuminate\Support\Facades\Mail;&lt;br&gt;
use Illuminate\Support\Facades\Log;&lt;/p&gt;

&lt;p&gt;class SendOrderConfirmation implements ShouldQueue&lt;br&gt;
{&lt;br&gt;
    use InteractsWithQueue;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * The number of times the job may be attempted.
 *
 * @var int
 */
public $tries = 3;

/**
 * Handle the event.
 *
 * @param  \App\Events\OrderPlaced  $event
 * @return void
 */
public function handle(OrderPlaced $event)
{
    $order = $event-&amp;gt;order;
    $user = $event-&amp;gt;user;

    try {
        Mail::to($user-&amp;gt;email)-&amp;gt;send(new OrderConfirmation($order));
        Log::info('Order confirmation email sent', ['order_id' =&amp;gt; $order-&amp;gt;id, 'user_id' =&amp;gt; $user-&amp;gt;id]);
    } catch (\Exception $e) {
        Log::error('Failed to send order confirmation email', ['order_id' =&amp;gt; $order-&amp;gt;id, 'user_id' =&amp;gt; $user-&amp;gt;id, 'error' =&amp;gt; $e-&amp;gt;getMessage()]);
        $this-&amp;gt;fail($e);
    }
}

/**
 * Handle a job failure.
 *
 * @param  \App\Events\OrderPlaced  $event
 * @param  \Throwable  $exception
 * @return void
 */
public function failed(OrderPlaced $event, $exception)
{
    Log::error('Order confirmation listener failed', ['order_id' =&amp;gt; $event-&amp;gt;order-&amp;gt;id, 'user_id' =&amp;gt; $event-&amp;gt;user-&amp;gt;id, 'error' =&amp;gt; $exception-&amp;gt;getMessage()]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;This listener has been implementing the &lt;em&gt;ShouldQueue&lt;/em&gt; interface, indicating that it should be queued. We have added error handling, logging, and defined a failed method to handle failures. The $tries property would be set to allow for multiple attempts in case of failure.&lt;br&gt;
Now, let us look at the UpdateInventory listener&lt;/p&gt;

&lt;p&gt;`namespace App\Listeners;&lt;/p&gt;

&lt;p&gt;use App\Events\OrderPlaced;&lt;br&gt;
use Illuminate\Contracts\Queue\ShouldQueue;&lt;br&gt;
use Illuminate\Queue\InteractsWithQueue;&lt;br&gt;
use Illuminate\Support\Facades\DB;&lt;br&gt;
use Illuminate\Support\Facades\Log;&lt;/p&gt;

&lt;p&gt;class UpdateInventory implements ShouldQueue&lt;br&gt;
{&lt;br&gt;
    use InteractsWithQueue;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Handle the event.
 *
 * @param  \App\Events\OrderPlaced  $event
 * @return void
 */
public function handle(OrderPlaced $event)
{
    $order = $event-&amp;gt;order;

    DB::transaction(function () use ($order) {
        foreach ($order-&amp;gt;items as $item) {
            $product = $item-&amp;gt;product;

            if ($product-&amp;gt;stock &amp;lt; $item-&amp;gt;quantity) {
                throw new \Exception("Insufficient stock for product: {$product-&amp;gt;id}");
            }

            $product-&amp;gt;decrement('stock', $item-&amp;gt;quantity);
            Log::info("Inventory updated", ['product_id' =&amp;gt; $product-&amp;gt;id, 'quantity' =&amp;gt; $item-&amp;gt;quantity]);
        }
    });
}

/**
 * Handle a job failure.
 *
 * @param  \App\Events\OrderPlaced  $event
 * @param  \Throwable  $exception
 * @return void
 */
public function failed(OrderPlaced $event, $exception)
{
    Log::error('Failed to update inventory', ['order_id' =&amp;gt; $event-&amp;gt;order-&amp;gt;id, 'error' =&amp;gt; $exception-&amp;gt;getMessage()]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Now, you'd understand that, this listener is there for a reasons like to upgrade the the inventory based on the order items etc. We have wrapped the inventory update in a database transaction to ensure data consistency. We have also added error checking to prevent negative stock and included logging for successful updates and failures.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Registering Events &amp;amp; Listeners&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
We will be registering these events and listeners in the EventServiceProvider&lt;/p&gt;

&lt;p&gt;`use App\Events\OrderPlaced;&lt;br&gt;
use App\Listeners\SendOrderConfirmation;&lt;br&gt;
use App\Listeners\UpdateInventory;&lt;/p&gt;

&lt;p&gt;class EventServiceProvider extends ServiceProvider&lt;br&gt;
{&lt;br&gt;
    /**&lt;br&gt;
     * The event listener mappings for the application.&lt;br&gt;
     *&lt;br&gt;
     * &lt;a class="mentioned-user" href="https://dev.to/var"&gt;@var&lt;/a&gt; array&lt;br&gt;
     */&lt;br&gt;
    protected $listen = [&lt;br&gt;
        OrderPlaced::class =&amp;gt; [&lt;br&gt;
            SendOrderConfirmation::class,&lt;br&gt;
            UpdateInventory::class,&lt;br&gt;
        ],&lt;br&gt;
    ];&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Register any events for your application.
 *
 * @return void
 */
public function boot()
{
    parent::boot();

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

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Dispatching Events:&lt;/p&gt;

&lt;p&gt;We can dispatch the event from a controller or service class&lt;/p&gt;

&lt;p&gt;`use App\Events\OrderPlaced;&lt;br&gt;
use App\Models\Order;&lt;br&gt;
use Illuminate\Http\Request;&lt;br&gt;
use Illuminate\Support\Facades\DB;&lt;/p&gt;

&lt;p&gt;class OrderController extends Controller&lt;br&gt;
{&lt;br&gt;
    /**&lt;br&gt;
     * Place a new order.&lt;br&gt;
     *&lt;br&gt;
     * &lt;a class="mentioned-user" href="https://dev.to/param"&gt;@param&lt;/a&gt;  \Illuminate\Http\Request  $request&lt;br&gt;
     * @return \Illuminate\Http\JsonResponse&lt;br&gt;
     */&lt;br&gt;
    public function placeOrder(Request $request)&lt;br&gt;
    {&lt;br&gt;
        $user = auth()-&amp;gt;user();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    DB::transaction(function () use ($request, $user) {
        $order = Order::create($request-&amp;gt;all());
        $order-&amp;gt;user()-&amp;gt;associate($user);
        $order-&amp;gt;save();

        event(new OrderPlaced($order, $user));
    });

    return response()-&amp;gt;json(['message' =&amp;gt; 'Order placed successfully', 'order_id' =&amp;gt; $order-&amp;gt;id]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In this example, we have wrapped the order creation and event dispatching in a database transaction to ensure that both occur successfully or not at all.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>php</category>
      <category>codingexamples</category>
    </item>
  </channel>
</rss>
