<?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>Forem: soheil-khaledabadi</title>
    <description>The latest articles on Forem by soheil-khaledabadi (@soheilkhaledabadi).</description>
    <link>https://forem.com/soheilkhaledabadi</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%2F1125583%2Fbf6595fe-3f54-4d88-8e1f-ab6a85f9d43b.jpeg</url>
      <title>Forem: soheil-khaledabadi</title>
      <link>https://forem.com/soheilkhaledabadi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/soheilkhaledabadi"/>
    <language>en</language>
    <item>
      <title>Introducing php-smart-validator : A Lightweight, Intuitive PHP Validation Package</title>
      <dc:creator>soheil-khaledabadi</dc:creator>
      <pubDate>Fri, 30 Aug 2024 10:24:45 +0000</pubDate>
      <link>https://forem.com/soheilkhaledabadi/introducing-php-smart-validator-a-lightweight-intuitive-php-validation-package-4ijf</link>
      <guid>https://forem.com/soheilkhaledabadi/introducing-php-smart-validator-a-lightweight-intuitive-php-validation-package-4ijf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Validating data is a crucial part of any web application. Whether you're developing a small website or a large-scale enterprise application, you need to ensure that your data is clean, consistent, and in the right format. Today, I'm excited to introduce &lt;strong&gt;&lt;code&gt;php-smart-validator&lt;/code&gt;&lt;/strong&gt;, a lightweight and intuitive PHP package designed to simplify data validation.&lt;/p&gt;

&lt;p&gt;In this post, I’ll walk you through the features of &lt;code&gt;php-smart-validator&lt;/code&gt;, how to install it, and provide a few examples to get you started!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Why &lt;code&gt;php-smart-validator&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With so many PHP validation libraries out there, you might wonder why I decided to create another one. The answer is simple: &lt;strong&gt;ease of use and flexibility&lt;/strong&gt;. &lt;code&gt;php-smart-validator&lt;/code&gt; is designed to provide a minimalistic yet powerful way to handle data validation without the bloat. It aims to reduce boilerplate code and improve readability while maintaining high flexibility and customizability.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Simple API&lt;/strong&gt;: Easy to use and understand, making validation quick to implement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight&lt;/strong&gt;: The package is minimal, ensuring it doesn’t bloat your application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible Rules&lt;/strong&gt;: Supports a variety of validation rules, and allows for custom rule creation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Error Messages&lt;/strong&gt;: Provides detailed and customizable error messages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chainable Rules&lt;/strong&gt;: Allows chaining of multiple rules for a single data point for better readability.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To start using &lt;code&gt;php-smart-validator&lt;/code&gt;, you’ll need to install it via Composer. Run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require geekgrove/php-smart-validator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, you can start validating data right away!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Basic Usage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s a quick example of how you can use &lt;code&gt;php-smart-validator&lt;/code&gt; to validate user input:&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;require&lt;/span&gt; &lt;span class="s1"&gt;'vendor/autoload.php'&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;GeekGrove\Validator\Validator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Sample data to validate&lt;/span&gt;
&lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'username'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'john_doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'john.doe@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'age'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Define validation rules&lt;/span&gt;
&lt;span class="nv"&gt;$rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'username'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|alpha_num|min:3|max:15'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'age'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|integer|min:18'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Create a new validator instance&lt;/span&gt;
&lt;span class="nv"&gt;$validator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$rules&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Run validation&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;$validator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fails&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Get validation errors&lt;/span&gt;
    &lt;span class="nv"&gt;$errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$validator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;print_r&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$errors&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Validation passed!"&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 the example above, we first define an array of data to validate and then set up our rules. The &lt;code&gt;Validator&lt;/code&gt; class takes care of the rest. If any of the data fails to pass the rules, the &lt;code&gt;fails&lt;/code&gt; method returns &lt;code&gt;true&lt;/code&gt;, and you can retrieve the error messages using the &lt;code&gt;errors&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Validation Rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the powerful features of &lt;code&gt;php-smart-validator&lt;/code&gt; is the ability to create custom validation rules. Here’s how you can add a custom rule to check if a username is unique:&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;$validator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;addRule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'unique_username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Check if username exists in database (example logic)&lt;/span&gt;
    &lt;span class="k"&gt;return&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;'username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&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;exists&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="s1"&gt;'The :attribute has already been taken.'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'username'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'|unique_username'&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;$validator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fails&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle validation errors&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this approach, you can tailor the validation process to suit the specific needs of your application, ensuring data integrity while providing clear feedback to users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Error Messages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php-smart-validator&lt;/code&gt; allows you to customize the error messages for each rule, making your validation process user-friendly and more informative:&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;$messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'username.required'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Please enter a username.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'email.email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'The email address format is invalid.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nv"&gt;$validator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$rules&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$messages&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;Chaining Rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can chain multiple rules for better readability and management:&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;$rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'username'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Validator&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'required'&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;rule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'alpha_num'&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;rule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'min'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&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;rule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'max'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&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;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php-smart-validator&lt;/code&gt; is a lightweight, flexible, and easy-to-use PHP validation package designed to simplify your development workflow. Whether you're a beginner or an experienced developer, you'll find it invaluable for ensuring data integrity and consistency in your projects.&lt;/p&gt;

&lt;p&gt;Give &lt;code&gt;php-smart-validator&lt;/code&gt; a try today, and let me know what you think! You can find the package on GitHub at &lt;a href="https://github.com/geekGroveOfficial/php-smart-validator" rel="noopener noreferrer"&gt;geekGroveOfficial/php-smart-validator&lt;/a&gt;. Contributions, feedback, and stars are all welcome!&lt;/p&gt;

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




&lt;p&gt;&lt;em&gt;Follow me for more updates on &lt;a href="https://github.com/soheilkhaledabdi" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 Build a Simple CRUD API in PHP with the Flight Framework</title>
      <dc:creator>soheil-khaledabadi</dc:creator>
      <pubDate>Fri, 23 Aug 2024 21:22:39 +0000</pubDate>
      <link>https://forem.com/soheilkhaledabadi/build-a-simple-crud-api-in-php-with-the-flight-framework-5fnk</link>
      <guid>https://forem.com/soheilkhaledabadi/build-a-simple-crud-api-in-php-with-the-flight-framework-5fnk</guid>
      <description>&lt;p&gt;Hello, fellow developers! 👋&lt;/p&gt;

&lt;p&gt;If you're looking for a straightforward and lightweight PHP framework to build a RESTful API, look no further than &lt;a href="http://flightphp.com/" rel="noopener noreferrer"&gt;Flight&lt;/a&gt;. Today, I'm excited to share a project I've been working on: a &lt;strong&gt;Simple CRUD API&lt;/strong&gt; built using the Flight framework. This project serves as a boilerplate for anyone looking to quickly get started with building a CRUD application in PHP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Flight?
&lt;/h2&gt;

&lt;p&gt;Flight is a micro-framework for PHP that makes it easy to build web applications. It’s minimal, fast, and perfect for small to medium-sized projects where you want to avoid the overhead of a full-fledged framework like Laravel or Symfony. Here are some reasons why you might choose Flight for your next project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight and Fast&lt;/strong&gt;: With a small footprint, Flight provides just what you need to build your application without any bloat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy to Learn&lt;/strong&gt;: If you're familiar with PHP, you can quickly grasp Flight's syntax and start building right away.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible&lt;/strong&gt;: Flight allows you to structure your application as you see fit, providing freedom without enforcing a rigid structure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  About the Project
&lt;/h2&gt;

&lt;p&gt;This project is a basic &lt;strong&gt;CRUD API&lt;/strong&gt; that demonstrates how to use Flight for handling requests, connecting to a MySQL database, and performing CRUD operations (Create, Read, Update, Delete). It’s a great starting point for beginners or a quick setup for experienced developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Basic CRUD Operations&lt;/strong&gt;: Simple routes for creating, reading, updating, and deleting records in a MySQL database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Configuration&lt;/strong&gt;: Easily configurable database settings to connect to your own MySQL instance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RESTful API Endpoints&lt;/strong&gt;: Uses standard HTTP methods to interact with the API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimal Setup&lt;/strong&gt;: Get up and running with minimal configuration and dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;To get started with the project, follow these steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Clone the Repository
&lt;/h3&gt;

&lt;p&gt;First, clone the repository from GitHub:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/soheilkhaledabdi/php-crud-api-flight.git
&lt;span class="nb"&gt;cd &lt;/span&gt;php-crud-api-flight
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Install Dependencies
&lt;/h3&gt;

&lt;p&gt;Install the Flight framework and any other dependencies using Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Configure Your Database
&lt;/h3&gt;

&lt;p&gt;Set up your database connection in &lt;code&gt;config/database.php&lt;/code&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;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'host'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'your_database_host'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'database'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'your_database_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'username'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'your_database_username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'your_database_password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'charset'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'utf8mb4'&lt;/span&gt;
   &lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Run the Project
&lt;/h3&gt;

&lt;p&gt;You can use PHP’s built-in server to run the project:&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="nb"&gt;cd &lt;/span&gt;public
php &lt;span class="nt"&gt;-S&lt;/span&gt; localhost:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, open your browser and go to &lt;code&gt;http://localhost:8000&lt;/code&gt; to see the API in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use the API
&lt;/h2&gt;

&lt;p&gt;Once the server is running, you can interact with the API using tools like Postman or &lt;code&gt;curl&lt;/code&gt;. Here’s a quick overview of the available endpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create a Record&lt;/strong&gt;: Send a POST request to &lt;code&gt;/create&lt;/code&gt; with JSON data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read Records&lt;/strong&gt;: Send a GET request to &lt;code&gt;/read&lt;/code&gt; to retrieve all records.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update a Record&lt;/strong&gt;: Send a PUT request to &lt;code&gt;/update/{id}&lt;/code&gt; with JSON data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete a Record&lt;/strong&gt;: Send a DELETE request to &lt;code&gt;/delete/{id}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Contribute
&lt;/h2&gt;

&lt;p&gt;If you have ideas to improve the project or find any bugs, feel free to open an issue or submit a pull request on GitHub. Contributions are always welcome!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This project is just a starting point, and there’s a lot more you can do with Flight. Whether you’re building a simple API or a more complex web application, Flight provides a flexible and lightweight solution.&lt;/p&gt;

&lt;p&gt;I hope this project helps you get started with Flight and PHP. Happy coding! 🎉&lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>Building an E-commerce Admin Panel with Laravel, Livewire, and Kotlin Multiplatform</title>
      <dc:creator>soheil-khaledabadi</dc:creator>
      <pubDate>Fri, 24 Nov 2023 14:08:50 +0000</pubDate>
      <link>https://forem.com/soheilkhaledabadi/building-an-e-commerce-admin-panel-with-laravel-livewire-and-kotlin-multiplatform-545i</link>
      <guid>https://forem.com/soheilkhaledabadi/building-an-e-commerce-admin-panel-with-laravel-livewire-and-kotlin-multiplatform-545i</guid>
      <description>&lt;p&gt;Hey Dev Community! 👋 Are you ready to delve into the realm of e-commerce management systems? I'm excited to share a project that combines the robustness of Laravel and Livewire for the admin panel, alongside Kotlin Multiplatform for a cross-platform shopping application.&lt;/p&gt;

&lt;p&gt;Overview&lt;/p&gt;

&lt;p&gt;Our aim was to craft an admin panel that streamlines the management of products, categories, and users, complemented by a dynamic API to foster seamless interactions with the shopping platform.&lt;/p&gt;

&lt;p&gt;Application&lt;/p&gt;

&lt;p&gt;Our shopping application, built with Jetpack Compose Multiplatform in Kotlin, empowers users to browse, search, and make purchases across Android and iOS devices with a user-friendly interface.&lt;/p&gt;

&lt;p&gt;Tech Stack&lt;/p&gt;

&lt;p&gt;Backend (Admin Panel):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel for a strong backend foundation&lt;/li&gt;
&lt;li&gt;Livewire for dynamic frontend interactions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cross-Platform Application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kotlin Multiplatform for shared UI components.&lt;/li&gt;
&lt;li&gt;Kotlin Coroutines for asynchronous tasks.&lt;/li&gt;
&lt;li&gt;Compose Multiplatform for declarative UI.&lt;/li&gt;
&lt;li&gt;Material3 for consistent design.&lt;/li&gt;
&lt;li&gt;Ktor for networking capabilities.&lt;/li&gt;
&lt;li&gt;Datastore for efficient local data storage.&lt;/li&gt;
&lt;li&gt;Precompose for streamlined development.&lt;/li&gt;
&lt;li&gt;Koin for dependency injection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Installation Guide&lt;/p&gt;

&lt;p&gt;Laravel Installation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clone the repository: git clone &lt;a href="https://github.com/soheilkhaledabdi/shop.git"&gt;https://github.com/soheilkhaledabdi/shop.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to the directory: cd shop&lt;/li&gt;
&lt;li&gt;Run composer install&lt;/li&gt;
&lt;li&gt;Create a copy of .env: cp .env.example .env&lt;/li&gt;
&lt;li&gt;Generate the application key: php artisan key:generate&lt;/li&gt;
&lt;li&gt;Execute migrations and seed the database: php artisan migrate --seed &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key Features&lt;/p&gt;

&lt;p&gt;Admin Dashboard: Seamlessly manage products, categories, &lt;br&gt;
orders, and customers.&lt;br&gt;
Laravel &amp;amp; Livewire: Harness Laravel's backend prowess with Livewire for reactive UI.&lt;br&gt;
Full API: Enable external integrations and interactions with the shopping platform.&lt;br&gt;
Table of Features&lt;/p&gt;

&lt;p&gt;Postman Collection&lt;/p&gt;

&lt;p&gt;Access the Postman Collection &lt;a href="https://documenter.getpostman.com/view/20769678/2s9Ye8fuf5"&gt;here&lt;/a&gt;. You can also download the JSON configuration file.&lt;/p&gt;

&lt;p&gt;Feel free to contribute to and enhance this project by visiting the repository &lt;a href="https://github.com/soheilkhaledabdi/shop"&gt;here&lt;/a&gt;. Your support by giving a star ⭐ is immensely appreciated!&lt;/p&gt;

&lt;p&gt;Let's collaborate and build remarkable solutions together! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>backend</category>
      <category>laravel</category>
    </item>
    <item>
      <title>A Comparative Analysis of Golang and Rust: Unraveling the Strengths and Trade-offs</title>
      <dc:creator>soheil-khaledabadi</dc:creator>
      <pubDate>Mon, 24 Jul 2023 10:15:01 +0000</pubDate>
      <link>https://forem.com/soheilkhaledabadi/a-comparative-analysis-of-golang-and-rust-unraveling-the-strengths-and-trade-offs-3gec</link>
      <guid>https://forem.com/soheilkhaledabadi/a-comparative-analysis-of-golang-and-rust-unraveling-the-strengths-and-trade-offs-3gec</guid>
      <description>&lt;p&gt;Golang (Go) and Rust are two powerful and emerging programming languages that have gained significant popularity in recent years. While both aim to address the challenges of modern software development, they have distinct design philosophies and cater to different use cases. This article aims to provide a comprehensive comparison between Golang and Rust, shedding light on their strengths, weaknesses, and use cases to help developers make informed decisions when choosing the appropriate language for their projects.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;1.Background and Origins:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Golang, also known as Go, was developed by Google in 2007 and released to the public in 2009. Its creators, Robert Griesemer, Rob Pike, and Ken Thompson, designed it with a focus on simplicity, efficiency, and concurrent programming.&lt;/p&gt;

&lt;p&gt;Rust, on the other hand, is a product of Mozilla Research, designed by Graydon Hoare. It was first announced in 2010 and reached its 1.0 stable version in 2015. Rust aims to provide memory safety without compromising on performance, making it suitable for system-level programming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Syntax and Ease of Learning:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both Golang and Rust offer straightforward syntax with an emphasis on readability and maintainability. Golang's syntax is similar to C, which makes it familiar to developers coming from C, C++, or Java backgrounds. On the other hand, Rust's syntax might require a bit more effort to grasp, especially for those new to low-level programming languages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Golang code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
package main

import "fmt"

func main() {
    fmt.Println("Hello, Golang!")
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Rust code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn main() {
    println!("Hello, Rust!");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Memory Management:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Golang uses a garbage collector to manage memory, automatically handling memory allocation and deallocation for developers. This approach simplifies memory management but may introduce some overhead in larger applications.&lt;/p&gt;

&lt;p&gt;Rust takes a different approach to memory management by utilizing a system of ownership and borrowing. It enforces strict rules at compile-time to ensure memory safety without relying on a garbage collector.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Concurrency and Parallelism:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Golang is renowned for its built-in support for concurrency through goroutines and channels. Goroutines are lightweight threads that allow developers to efficiently handle concurrent tasks. Channels facilitate communication and synchronization between goroutines.&lt;br&gt;
Rust, on the other hand, provides concurrency through async/await and multi-threading. Its async/await feature allows developers to write asynchronous code, while multi-threading enables true parallelism in CPU-bound tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Golang concurrency:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

func worker(id int, jobs &amp;lt;-chan int, results chan&amp;lt;- int) {
    for j := range jobs {
        fmt.Println("Worker", id, "processing job", j)
        results &amp;lt;- j * 2
    }
}

func main() {
    jobs := make(chan int, 100)
    results := make(chan int, 100)

    for w := 1; w &amp;lt;= 3; w++ {
        go worker(w, jobs, results)
    }

    for j := 1; j &amp;lt;= 5; j++ {
        jobs &amp;lt;- j
    }
    close(jobs)

    for a := 1; a &amp;lt;= 5; a++ {
        &amp;lt;-results
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Rust concurrency:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use std::thread;
use std::sync::mpsc;
use std::sync::Arc;
use std::sync::Mutex;

fn worker(id: usize, jobs: Arc&amp;lt;Mutex&amp;lt;Vec&amp;lt;i32&amp;gt;&amp;gt;&amp;gt;, results: mpsc::Sender&amp;lt;i32&amp;gt;) {
    while let Some(job) = jobs.lock().unwrap().pop() {
        println!("Worker {} processing job {}", id, job);
        results.send(job * 2).unwrap();
    }
}

fn main() {
    let (results_tx, results_rx) = mpsc::channel();
    let jobs = Arc::new(Mutex::new(vec![1, 2, 3, 4, 5]));

    let mut handles = vec![];

    for id in 1..=3 {
        let jobs = jobs.clone();
        let results_tx = results_tx.clone();
        let handle = thread::spawn(move || {
            worker(id, jobs, results_tx);
        });
        handles.push(handle);
    }

    for handle in handles {
        handle.join().unwrap();
    }

    drop(results_tx);

    for result in results_rx {
        println!("Result: {}", result);
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.Performance and Compilation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Examine the performance characteristics of Golang and Rust. Compare their compilation processes, runtime overhead, and execution speeds for various types of applications. Present benchmark results for real-world use cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.Safety and Error Handling:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Discuss the safety features in Golang and Rust, such as Golang's type system and Rust's strict ownership model. Compare their error handling mechanisms, including error types and exception handling, and their impact on code reliability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7.Ecosystem and Libraries:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Evaluate the maturity of the ecosystems surrounding Golang and Rust. Compare the availability and quality of libraries, frameworks, and tools for both languages. Discuss how the ecosystems support various application domains.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8.Community and Support:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Analyze the size, activity, and supportiveness of the Golang and Rust communities. Explore the resources available for learning and troubleshooting, such as documentation, forums, and open-source contributions.&lt;br&gt;
Use Cases and Real-World Examples:&lt;br&gt;
Provide real-world use cases where Golang and Rust excel and discuss why they are preferred in those scenarios. Highlight success stories and case studies of projects built with each language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you for your time&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>rust</category>
      <category>programming</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
