<?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: MD Shahin Mia Robin</title>
    <description>The latest articles on DEV Community by MD Shahin Mia Robin (@robinncode).</description>
    <link>https://dev.to/robinncode</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%2F1091664%2F1b99e1ca-c704-4c94-9c4e-d0145632cdd4.png</url>
      <title>DEV Community: MD Shahin Mia Robin</title>
      <link>https://dev.to/robinncode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/robinncode"/>
    <language>en</language>
    <item>
      <title>Workflow of Laravel Eloquent ORM behind the scenes</title>
      <dc:creator>MD Shahin Mia Robin</dc:creator>
      <pubDate>Fri, 01 Aug 2025 15:16:55 +0000</pubDate>
      <link>https://dev.to/robinncode/workflow-of-laravel-eloquent-orm-behind-the-scenes-2n60</link>
      <guid>https://dev.to/robinncode/workflow-of-laravel-eloquent-orm-behind-the-scenes-2n60</guid>
      <description>&lt;p&gt;Laravel Eloquent ORM is an Active Record implementation that abstracts SQL operations into expressive PHP syntax using models. Behind every Eloquent call, Laravel translates your methods into raw SQL using a layered structure of classes.&lt;/p&gt;

&lt;p&gt;🔁 &lt;strong&gt;Eloquent Internal Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you call an Eloquent method (e.g., User::where(...)-&amp;gt;first()), Laravel processes it through these core steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Model Instantiation:&lt;/strong&gt;&lt;br&gt;
Laravel bootstraps your model (e.g., User extends Model) and applies traits (like HasAttributes, HasRelationships, etc.).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Query Builder Initialization:&lt;/strong&gt;&lt;br&gt;
The newQuery() method returns an instance of Illuminate\Database\Eloquent\Builder, which wraps the core Illuminate\Database\Query\Builder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. SQL Compilation:&lt;/strong&gt;&lt;br&gt;
Query Builder methods like -&amp;gt;where() or -&amp;gt;with() are chained and eventually converted into raw SQL by the toSql() method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Database Connection &amp;amp; Execution:&lt;/strong&gt;&lt;br&gt;
Laravel uses DB::connection() and PDO to execute the query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Hydration into Models:&lt;/strong&gt;&lt;br&gt;
The raw database rows are converted (hydrated) into fully functional Eloquent model instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Model Events &amp;amp; Mutators:&lt;/strong&gt;&lt;br&gt;
Laravel triggers lifecycle events like retrieved, saving, etc., and applies accessors/mutators if defined.&lt;/p&gt;

&lt;p&gt;🧪 &lt;strong&gt;Example 1: Query Builder&lt;/strong&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="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;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'jane@example.com'&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;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 Behind the scenes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'jane@example.com'&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Laravel executes this, then hydrates the result into a User object.&lt;/p&gt;

&lt;p&gt;🧪 &lt;strong&gt;Example 2: hasOne Relationship&lt;/strong&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="c1"&gt;// app/Models/User.php&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasOne&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Profile&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="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// On Controller&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Auto-fetches from DB&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔍 &lt;strong&gt;Internally:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;profiles&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Laravel hydrates the result into a Profile model and attaches it to the $user object.&lt;/p&gt;

&lt;p&gt;🧪 &lt;strong&gt;Example 3: belongsTo Relationship&lt;/strong&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="c1"&gt;// app/Models/Profile.php&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;belongsTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;User&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="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// On controller&lt;/span&gt;
&lt;span class="nv"&gt;$profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Profile&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="mi"&gt;10&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="nv"&gt;$profile&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔍 &lt;strong&gt;Internally:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, Laravel hydrates the User result and associates it with the Profile instance.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Key Takeaways:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eloquent sits on top of Laravel's Query Builder and PDO.&lt;/li&gt;
&lt;li&gt;Relationships like hasOne and belongsTo internally generate foreign key–based queries.&lt;/li&gt;
&lt;li&gt;Eloquent uses hydration, events, and casting to make model objects fully interactive.&lt;/li&gt;
&lt;li&gt;Under the hood, it’s still structured SQL, just with expressive syntax and clean abstraction.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>orm</category>
    </item>
    <item>
      <title>Standardizing Git Commit Messages: The Role of Tags like wip and Beyond</title>
      <dc:creator>MD Shahin Mia Robin</dc:creator>
      <pubDate>Mon, 05 May 2025 01:22:05 +0000</pubDate>
      <link>https://dev.to/robinncode/standardizing-git-commit-messages-the-role-of-tags-like-wip-and-beyond-lpe</link>
      <guid>https://dev.to/robinncode/standardizing-git-commit-messages-the-role-of-tags-like-wip-and-beyond-lpe</guid>
      <description>&lt;p&gt;In modern software engineering, the clarity of your Git commit messages significantly impacts project maintainability, collaboration, and release workflows. While wip (Work In Progress) is often used to denote an incomplete task, teams should adopt standardized tags that better reflect the intent and nature of each change.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the &lt;code&gt;wip&lt;/code&gt; Tag
&lt;/h3&gt;

&lt;p&gt;wip is a temporary marker indicating that the commit includes unfinished work. It is useful during active development to back up code or share early drafts. However, wip commits should not be merged into main or release branches. Before merging, squash, or clean these commits into meaningful messages.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wip(ui): started implementing dashboard layout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Recommended Commit Tags and Examples
&lt;/h3&gt;

&lt;p&gt;Below are the standard commit tags, widely used in the &lt;a href="https://www.conventionalcommits.org/en/v1.0.0/" rel="noopener noreferrer"&gt;Conventional Commits&lt;/a&gt; specification:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;feat&lt;/code&gt;: New feature addition&lt;br&gt;
Use when adding a new capability or feature.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;feat(auth): add JWT-based authentication middleware
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;fix&lt;/code&gt;: Bug fix or error resolution&lt;br&gt;
Use when resolving a defect or error in the code.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fix(payment): resolve rounding error in tax calculation
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;docs&lt;/code&gt;: Documentation-only changes&lt;br&gt;
Use for updates to markdown, code comments, or technical guides.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docs(readme): update API usage section with latest endpoints
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;style&lt;/code&gt;: Formatting and style updates&lt;br&gt;
Use when making changes that do not affect code logic—e.g., indentation, whitespaces, or semicolon adjustments.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;style(ui): reformat button component for consistency
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;refactor&lt;/code&gt;: Code refactoring&lt;br&gt;
Use for structural changes that neither fix a bug nor add a feature.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;refactor(order-service): simplify loop logic for item parsing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;test&lt;/code&gt;: Adding or updating tests&lt;br&gt;
Use for adding new tests or modifying existing test coverage.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test(profile): add integration tests for avatar upload
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;chore&lt;/code&gt;: Maintenance tasks&lt;br&gt;
Use for routine tasks like dependency upgrades or tool configuration updates.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chore(deps): update laravel/framework to v10.3.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;perf&lt;/code&gt;: Performance improvements&lt;br&gt;
Use for code changes that enhance performance.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;perf(query): optimize join condition to reduce query time
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ci&lt;/code&gt;: CI/CD pipeline or config updates&lt;br&gt;
Use for changes related to continuous integration or deployment.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ci(github): add linting step to pull request workflow
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Commit Message Structure Format
&lt;/h3&gt;

&lt;p&gt;To standardize further, follow this format:&lt;br&gt;
&amp;lt;type&amp;gt;(&amp;lt;scope&amp;gt;): &amp;lt;short description&amp;gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;type = tag from above&lt;/li&gt;
&lt;li&gt;scope = optional module or component name&lt;/li&gt;
&lt;li&gt;description = concise message summarizing the change&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Recommendations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Avoid leaving wip in history; squash or reword before merging.&lt;/li&gt;
&lt;li&gt;Use tags consistently across all commits.&lt;/li&gt;
&lt;li&gt;Validate commit messages with a Git hook or CI job for enforcement.&lt;/li&gt;
&lt;li&gt;Maintain readability and professionalism in all messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A well-maintained commit history is a living logbook of a project’s evolution. Adopt structured commit standards today for long-term agility and clarity.&lt;/p&gt;

&lt;p&gt;Note: The Article was written and the cover image generated by ChatGPT.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>cleancode</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>The Importance of Writing Meaningful Code and Documentation</title>
      <dc:creator>MD Shahin Mia Robin</dc:creator>
      <pubDate>Wed, 15 Jan 2025 20:40:32 +0000</pubDate>
      <link>https://dev.to/robinncode/the-importance-of-writing-meaningful-code-and-documentation-454a</link>
      <guid>https://dev.to/robinncode/the-importance-of-writing-meaningful-code-and-documentation-454a</guid>
      <description>&lt;p&gt;As developers, many of us believe that our primary responsibility is to understand the requirements and hastily write code to meet them. However, this is a flawed notion. Among the many responsibilities of a developer, writing proper documentation is also crucial. Unfortunately, this is often misunderstood or poorly executed. Some developers write so extensively that the core requirements or business logic get lost—a case of "using a cannon to kill a mosquito."&lt;/p&gt;

&lt;p&gt;Simply writing line-by-line documentation doesn't automatically make your code readable. Documentation should focus only on what is essential, especially when it explains critical project requirements or business logic. This doesn't mean you should neglect documentation entirely for straightforward cases; instead, well-written, self-explanatory code often eliminates the need for excessive documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Striking the Right Balance in Documentation and Code
&lt;/h3&gt;

&lt;p&gt;A common scenario involves working with database tables to check if data exists or to count the number of rows for further processing. For repetitive tasks like this, a helper function is an excellent solution. Consider the following 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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BaseModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Models&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getTotalCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$table_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$condition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SELECT COUNT(*) AS total_rows FROM "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$table_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$condition&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;" WHERE "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$condition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&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;get&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="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="nv"&gt;$productTotalCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;BaseModel&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getTotalCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'brand_id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$brand_id&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$productTotalCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Further processing...&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 is clear and concise, with no unnecessary complexity. The function serves its purpose effectively, and its usage is intuitive. However, let’s look at a contrasting 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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;My_Model&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Models&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
     * Get Simple Read Of Method
     * to get a specific row of a table
     */&lt;/span&gt;
    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;simple_read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$table_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$condition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$column_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$table_name&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;$condition&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&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;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$column_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$condition&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;get_where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$table_name&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;row&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="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="nv"&gt;$productTotalCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;My_Model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;simple_read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'brand_id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$brand_id&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$productTotalCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Further processing...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the simple_read function is being misused for a task it wasn’t designed for. If the products table has 20 rows, the function will return only the first row of the table. If no data is present, it returns NULL. This creates a problem: is NULL comparable to 0? Absolutely not. Consequently, the code will throw an error if the table has no data. Writing detailed documentation for such flawed code won’t make it better. It’s akin to adding layers of explanation to a fundamentally broken solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lessons Learned:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Prioritize Clarity in Code: Strive to write clear and self-explanatory code. If your code is easy to understand, it reduces the need for extensive documentation.&lt;/li&gt;
&lt;li&gt;Avoid Misuse of Functions: Understand the purpose of each function and use it appropriately. Avoid bending a function's behavior to fit a task it wasn’t designed for.&lt;/li&gt;
&lt;li&gt;Focus on the Essentials: Documentation should highlight what truly matters, such as critical business logic or non-obvious functionality.&lt;/li&gt;
&lt;li&gt;Think Before You Code: As the saying goes, "Think before you act." Similarly, write code after careful thought and planning. Don’t defend flawed practices under the guise of meeting deadlines.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By balancing meaningful documentation and well-structured code, developers can ensure their work is efficient and easy to maintain. Ultimately, it’s not just about writing code; it’s about writing good code.&lt;/p&gt;

</description>
      <category>php</category>
      <category>codeigniter4</category>
      <category>codeigniter3</category>
      <category>documentation</category>
    </item>
    <item>
      <title>Integrate Swagger UI with Codeigniter4</title>
      <dc:creator>MD Shahin Mia Robin</dc:creator>
      <pubDate>Mon, 16 Dec 2024 10:03:32 +0000</pubDate>
      <link>https://dev.to/robinncode/integrate-swagger-ui-with-codeigniter4-47je</link>
      <guid>https://dev.to/robinncode/integrate-swagger-ui-with-codeigniter4-47je</guid>
      <description>&lt;p&gt;Swagger is a widely used API documentation and testing tool that seamlessly integrates with popular web frameworks like Laravel, Spring Boot, CodeIgniter, and ExpressJS. In this article, we will focus on integrating Swagger with CodeIgniter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Dependencies:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="n"&gt;composer&lt;/span&gt; &lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="n"&gt;zircote&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;swagger&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="n"&gt;doctrine&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;annotations&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Downloading the SwaggerUI &lt;code&gt;.zip&lt;/code&gt; or SwaggerUI GitHub repo:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Download link: &lt;a href="https://github.com/swagger-api/swagger-ui/releases" rel="noopener noreferrer"&gt;SwaggerUI latest releases&lt;/a&gt;
Download the Swagger UI release that best fits your requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Writing the Controller:
&lt;/h3&gt;

&lt;p&gt;To generate the swagger.json file for Swagger UI we will have to create a controller. Name the controller as your choice we are giving it &lt;code&gt;SwaggerDocGenerator.php&lt;/code&gt;. In the controller, we will have to use &lt;code&gt;OpenApi\Generator&lt;/code&gt; from &lt;code&gt;zircote/swagger-php&lt;/code&gt; to convert all the &lt;code&gt;@OA&lt;/code&gt; syntax into a JSON.&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;?php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Controllers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenApi\Generator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SwaggerDocGenerator&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;BaseController&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
     * Generate OpenAPI documentation for the API ...
     * @return string
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Specify the path where your API controllers are located&lt;/span&gt;
        &lt;span class="nv"&gt;$openapi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Generator&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="no"&gt;APPPATH&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'Controllers'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

        &lt;span class="nv"&gt;$swaggerContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$openapi&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;toJson&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Save the generated OpenAPI content to a file&lt;/span&gt;
        &lt;span class="nv"&gt;$filePath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;FCPATH&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'swagger_ui/swagger.json'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;file_put_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$filePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$swaggerContent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$swaggerContent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * Render the SwaggerUI ...
     * @return string
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;()&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;'swagger_docs/index'&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="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating Routes:
&lt;/h3&gt;

&lt;p&gt;By creating a route on &lt;code&gt;Config/Routes.php&lt;/code&gt; we will be able to generate the expected &lt;code&gt;sawgger.json&lt;/code&gt; file.&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="c1"&gt;// Create API documentation ...&lt;/span&gt;
&lt;span class="nv"&gt;$routes&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;'api/v1/docs/generate'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SwaggerDocGenerator::generate'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$routes&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;'api/v1/docs/ui'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SwaggerDocGenerator::index'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rendering Swagger UI:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  There are many ways to render your swagger.json file into SwaggerUI:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Importing the swagger.json file into the POSTMAN.&lt;/li&gt;
&lt;li&gt;Using the SwaggerUI with your own views to render the SwaggerUI.&lt;/li&gt;
&lt;li&gt;Setting up the environment into your frontend application to render the SwaggerUI by requesting on backend-API for the swagger.json file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this, we will see the first two ways. We will talk about the 3rd way in another article.&lt;/p&gt;

&lt;h4&gt;
  
  
  Importing the swagger.json file into the POSTMAN:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Copy the swagger.json.&lt;/li&gt;
&lt;li&gt;Open the POSTMAN.&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Import&lt;/code&gt; button in the top-left corner.&lt;/li&gt;
&lt;li&gt;Paste the copied swagger.json.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Using the SwaggerUI with your own views to render the SwaggerUI:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create a .php file on your views folder &lt;code&gt;app/Views/swagger_docs/index.php&lt;/code&gt; to render the SwaggerUI.&lt;/li&gt;
&lt;li&gt;Extract the downloaded SwaggerUI &lt;code&gt;.zip&lt;/code&gt; file into the &lt;code&gt;public/swagger_ui/&lt;/code&gt; folder.
&lt;/li&gt;
&lt;/ul&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&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&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;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Swagger UI&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/swagger-ui.css'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/index.css'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/png"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/favicon-32x32.png'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"32x32"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/png"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/favicon-16x16.png'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"16x16"&lt;/span&gt; &lt;span class="nt"&gt;/&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;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"swagger-ui"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/swagger-ui-bundle.js'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/swagger-ui-standalone-preset.js'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt; &lt;span class="nf"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'swagger_ui/swagger-initializer.js'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&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;Now, we have to update the url of &lt;code&gt;public\swagger_ui\swagger-initializer.js&lt;/code&gt; with the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://your-local-server/swagger_ui/swagger.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Make sure to run the &lt;code&gt;php spark serve&lt;/code&gt; command to run the Codeigniter4 application.&lt;/li&gt;
&lt;li&gt;Every time you make changes in the OpenAPI documentation syntax, you will have to run the &lt;code&gt;http://localhost:8080/api/v1/docs/generate&lt;/code&gt; URL to generate the updated &lt;code&gt;swagger.json&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Make sure to update the &lt;code&gt;swagger-initializer.js&lt;/code&gt; file with the updated URL of the &lt;code&gt;swagger.json&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;In this article, we explored integrating Swagger with CodeIgniter 4, generating the &lt;code&gt;swagger.json&lt;/code&gt; file, rendering it in Swagger UI, and importing it into Postman. We also demonstrated how to render Swagger UI within custom views. However, manually generating the &lt;code&gt;swagger.json&lt;/code&gt; file and updating the URL in the &lt;code&gt;swagger-initializer.js&lt;/code&gt; file is not ideal.&lt;/p&gt;

&lt;p&gt;In the next article, I will demonstrate automating this process using custom CLI commands and aim to develop an open-source package for this purpose. Feel free to share your suggestions or queries in the comments section.&lt;/p&gt;

</description>
      <category>php</category>
      <category>codeigniter4</category>
      <category>swagger</category>
      <category>apidocumentation</category>
    </item>
    <item>
      <title>Getting migration and seeder files from connected DB using db_craft</title>
      <dc:creator>MD Shahin Mia Robin</dc:creator>
      <pubDate>Sun, 06 Aug 2023 06:45:12 +0000</pubDate>
      <link>https://dev.to/robinncode/getting-migration-and-seeder-files-from-connected-db-using-dbcraft-130n</link>
      <guid>https://dev.to/robinncode/getting-migration-and-seeder-files-from-connected-db-using-dbcraft-130n</guid>
      <description>&lt;h2&gt;
  
  
  DB-Craft
&lt;/h2&gt;

&lt;h3&gt;
  
  
  DB-Craft is a package for CodeIgniter 4 that provides convenient commands to generate migration and seeder files from a connected database.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;You can install the DB-Craft package via Composer by running the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dependencies
&lt;/h3&gt;

&lt;p&gt;DB-Craft has the following dependencies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;PHP: ^7.0.* || ^8.0.*&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CodeIgniter/Framework: ^4.0.*&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;p&gt;DB-Craft comes with the following commands:&lt;br&gt;
Generate Migration Files&lt;/p&gt;

&lt;p&gt;To generate all migration files from the connected database, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php spark get:migration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To generate migration files for a specific table, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php spark get:migration table_name 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;table_name&lt;/code&gt; with the name of the specific table for which you want to generate migration files.&lt;br&gt;
Generate Seeder Files&lt;/p&gt;

&lt;p&gt;To generate all seeder files from the connected database, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php spark get:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To generate seeder files for a specific table with table data, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php spark get:seed table_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;table_name&lt;/code&gt; with the name of the specific table for which you want to generate seeder files.&lt;/p&gt;

</description>
      <category>codeigniter4</category>
      <category>php</category>
      <category>migration</category>
      <category>seeder</category>
    </item>
  </channel>
</rss>
