<?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: Code Of Accuracy</title>
    <description>The latest articles on DEV Community by Code Of Accuracy (@codeofaccuracy).</description>
    <link>https://dev.to/codeofaccuracy</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%2F1047539%2F2dc39b40-3d9a-4627-b446-b4cd0c6c6889.png</url>
      <title>DEV Community: Code Of Accuracy</title>
      <link>https://dev.to/codeofaccuracy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codeofaccuracy"/>
    <language>en</language>
    <item>
      <title>async &amp; await</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Thu, 20 Apr 2023 09:09:26 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/async-await-4a9f</link>
      <guid>https://dev.to/codeofaccuracy/async-await-4a9f</guid>
      <description>&lt;p&gt;Asynchronous programming in JavaScript can be a bit challenging, especially when dealing with code that depends on network requests or other long-running tasks. However, the introduction of the &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keywords in &lt;code&gt;ES2017 (also known as ES8)&lt;/code&gt; has greatly simplified asynchronous programming in JavaScript. In this article, we'll explore what &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; are, and how to use them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are async and await?&lt;/strong&gt;&lt;br&gt;
           &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; are two new keywords introduced in ES2017 that simplify asynchronous programming in JavaScript. The &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;async&lt;/code&gt; keyword is used to define an asynchronous function, which returns a promise that is resolved with the function's return value. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;await&lt;/code&gt; keyword is used to pause the execution of an &lt;code&gt;async&lt;/code&gt; function until a promise is resolved.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An async function is defined like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function myAsyncFunction() {
  // Code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside an &lt;code&gt;async&lt;/code&gt; function, you can use the &lt;code&gt;await&lt;/code&gt; keyword to pause the function execution until a promise is resolved. The syntax for using await looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = await myPromise;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;myPromise&lt;/code&gt; is a promise that you want to wait for, and result is the value that the promise resolves to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fetching data from an API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's take a look at an example that demonstrates how to use &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; to fetch data from an API.&lt;/p&gt;

&lt;p&gt;Suppose we have an API endpoint that returns a list of users. The endpoint is available at &lt;a href="https://jsonplaceholder.typicode.com/users"&gt;https://jsonplaceholder.typicode.com/users&lt;/a&gt;. We want to fetch this data and log the names of the users to the console.&lt;/p&gt;

&lt;p&gt;Here's how we can do it using &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function getUsers() {
  try {
    const response = await fetch('https://jsonplaceholder.typicode.com/users');
    const data = await response.json();
    const names = data.map(user =&amp;gt; user.name);
    console.log(names);
  } catch (error) {
    console.error(error);
  }
}

getUsers();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we define an &lt;code&gt;async&lt;/code&gt; function called &lt;code&gt;getUsers&lt;/code&gt; that fetches the data from the API using the &lt;code&gt;fetch&lt;/code&gt; function. We then use the &lt;code&gt;await&lt;/code&gt; keyword to &lt;code&gt;pause&lt;/code&gt; the function execution until the data is fetched and parsed as JSON using the json method of the response object.&lt;/p&gt;

&lt;p&gt;Once we have the data as an array of user objects, we use the &lt;code&gt;map&lt;/code&gt; method to extract the name property of each user, and then log the resulting array of names to the console.&lt;/p&gt;

&lt;p&gt;In case there's an error during the fetch or parsing process, we handle it using a &lt;code&gt;try-catch&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;Finally, we call the &lt;code&gt;getUsers&lt;/code&gt; function to start the asynchronous operation.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://replit.com/@CodeOf1/asyncawait"&gt;https://replit.com/@CodeOf1/asyncawait&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://replit.com/@CodeOf1/asyncawait02"&gt;https://replit.com/@CodeOf1/asyncawait02&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Promises in Javascript</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Mon, 17 Apr 2023 06:39:17 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/promises-in-javascript-2e09</link>
      <guid>https://dev.to/codeofaccuracy/promises-in-javascript-2e09</guid>
      <description>&lt;p&gt;In JavaScript, a Promise is a built-in object that represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. It provides a cleaner and more organized way to handle asynchronous code, avoiding the infamous &lt;code&gt;callback hell&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's an example of how to use &lt;code&gt;Promises&lt;/code&gt; in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getData = () =&amp;gt; {
  return new Promise((resolve, reject) =&amp;gt; {
    // Perform an asynchronous operation, such as fetching data from an API Currently we are taking static data for example.
    const data = { id: 1, name: "Sam Adam" };
    if (data) {
      // If the operation is successful, call the "resolve" method with the data
      resolve(data);
    } else {
      // If there's an error, call the "reject" method with the error message
      reject("Error: Unable to retrieve data.");
    }
  });
};

// Call the Promise function and handle the response using "then" and "catch" methods
getData()
  .then((data) =&amp;gt; {
    console.log("Data retrieved successfully:", data);
  })
  .catch((error) =&amp;gt; {
    console.error("Error occurred while retrieving data:", error);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the &lt;code&gt;getData()&lt;/code&gt; function returns a Promise object, which performs an &lt;code&gt;asynchronous&lt;/code&gt; operation of fetching data from an API. If the operation is successful, the Promise calls the &lt;code&gt;resolve()&lt;/code&gt; method with the data, and if there's an error, it calls the &lt;code&gt;reject()&lt;/code&gt; method with the error message.&lt;/p&gt;

&lt;p&gt;To handle the response from the Promise, you can use the &lt;code&gt;then()&lt;/code&gt; and &lt;code&gt;catch()&lt;/code&gt; methods. The &lt;code&gt;then()&lt;/code&gt; method is called when the Promise is resolved successfully, and it receives the data as a parameter. The &lt;code&gt;catch()&lt;/code&gt; method is called when the Promise is rejected with an error, and it receives the error message as a parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chaining Promises&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;const getData = () =&amp;gt; {
  return new Promise((resolve, reject) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      const data = { id: 1, name: "John Doe" };
      if (data) {
        resolve(data);
      } else {
        reject(new Error("Unable to retrieve data."));
      }
    }, 2000);
  });
};

const getDetails = (data) =&amp;gt; {
  return new Promise((resolve, reject) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      const details = { age: 30, city: "New York" };
      if (details) {
        resolve({ ...data, ...details });
      } else {
        reject(new Error("Unable to retrieve details."));
      }
    }, 2000);
  });
};

getData()
  .then(getDetails)
  .then((result) =&amp;gt; {
    console.log(result); // Output: { id: 1, name: "John Doe", age: 30, city: "New York" }
  })
  .catch((error) =&amp;gt; {
    console.error(error);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we have two Promises, &lt;code&gt;getData()&lt;/code&gt; and &lt;code&gt;getDetails()&lt;/code&gt;, that simulate fetching data from an API. The &lt;code&gt;getDetails()&lt;/code&gt; Promise depends on the data returned by the &lt;code&gt;getData()&lt;/code&gt; Promise. We use the &lt;code&gt;then()&lt;/code&gt; method to chain these Promises together. The &lt;code&gt;then()&lt;/code&gt; method takes a callback function that returns another Promise. The value returned by the first Promise is passed as an argument to the callback function of the second Promise. This process can be repeated as many times as necessary.&lt;/p&gt;

&lt;p&gt;We use the &lt;code&gt;getData()&lt;/code&gt; Promise to retrieve some data, and then chain the &lt;code&gt;getDetails()&lt;/code&gt; Promise to retrieve additional details about that data. Finally, we use the &lt;code&gt;then()&lt;/code&gt; method to log the result of both Promises chained together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.all()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Promise.all()&lt;/code&gt; method allows you to run multiple Promises in parallel and wait for all of them to complete. This method takes an array of Promises as its argument and returns a new Promise that is fulfilled when all of the Promises in the array have been fulfilled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise1 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 2000, "foo"));
const promise2 = 10;
const promise3 = new Promise((resolve) =&amp;gt;
  setTimeout(resolve, 3000, "bar")
);

Promise.all([promise1, promise2, promise3]).then((values) =&amp;gt;
  console.log(values)
);
// Output: ["foo", 10, "bar"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we create three Promises and pass them to the &lt;code&gt;Promise.all()&lt;/code&gt; method. The &lt;code&gt;then()&lt;/code&gt; method is used to log the array of values returned by the Promises when they are all fulfilled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.race()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Promise.race()&lt;/code&gt; method allows you to run multiple Promises in parallel and return the value of the first Promise that is fulfilled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise1 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 2000, "foo"));
const promise2 = new Promise((resolve) =&amp;gt;
  setTimeout(resolve, 3000, "bar")
);

Promise.race([promise1, promise2]).then((value) =&amp;gt; console.log(value));
// Output: "foo"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we create two Promises and pass them to the &lt;code&gt;Promise.race()&lt;/code&gt; method. The &lt;code&gt;then()&lt;/code&gt; method is used to log the value of the first Promise that is fulfilled. In this case, &lt;code&gt;promise1&lt;/code&gt; is fulfilled first, so its value ("foo") is logged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.allSettled()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.allSettled()&lt;/code&gt; was introduced in ES2020. It takes an array of Promises as its input and returns a new Promise that resolves to an array of objects, one for each Promise in the input array. Each object in the resulting array represents the state of the corresponding Promise and contains two properties:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;status:&lt;/strong&gt; The status of the Promise. It can be either "fulfilled" or "rejected".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;value or reason:&lt;/strong&gt; Depending on whether the Promise was fulfilled or rejected, this property contains either the fulfilled value or the rejection reason.&lt;/p&gt;

&lt;p&gt;Here's an example of how Promise.allSettled() works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promises = [
  Promise.resolve("resolved"),
  Promise.reject("rejected"),
  Promise.resolve("resolved again"),
];

Promise.allSettled(promises).then((results) =&amp;gt; console.log(results));
// Output: [
//   { status: "fulfilled", value: "resolved" },
//   { status: "rejected", reason: "rejected" },
//   { status: "fulfilled", value: "resolved again" }
// ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create an array of three Promises. The first and third Promises are fulfilled with the values "resolved" and "resolved again", respectively. The second Promise is rejected with the reason "rejected". We then pass this array of Promises to &lt;code&gt;Promise.allSettled()&lt;/code&gt;, which returns a new Promise that resolves to an array of three objects representing the state of each Promise. The &lt;code&gt;then()&lt;/code&gt; method is used to log the resulting array of objects to the console.&lt;/p&gt;

&lt;p&gt;Note that unlike &lt;code&gt;Promise.all()&lt;/code&gt;, &lt;code&gt;Promise.allSettled()&lt;/code&gt; waits for all Promises to settle (i.e., either fulfill or reject), regardless of their outcome. This means that even if some of the Promises are rejected, the resulting Promise returned by &lt;code&gt;Promise.allSettled()&lt;/code&gt; will still resolve with an array of objects representing the state of all the Promises.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repl as Example :&lt;/strong&gt; &lt;a href="https://replit.com/@CodeOf1/PromisesAPI"&gt;https://replit.com/@CodeOf1/PromisesAPI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Summary&lt;/code&gt;&lt;br&gt;
Promises are a powerful tool in JavaScript for working with asynchronous code. They allow you to handle the success and failure of asynchronous operations in a more structured and readable way. In addition to the &lt;code&gt;then()&lt;/code&gt; and &lt;code&gt;catch()&lt;/code&gt; methods, you can also chain Promises together with the &lt;code&gt;then()&lt;/code&gt; method, and run multiple Promises in parallel with the &lt;code&gt;Promise.all()&lt;/code&gt; and &lt;code&gt;Promise.race()&lt;/code&gt; methods.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>promises</category>
      <category>codeofaccuracy</category>
    </item>
    <item>
      <title>Collection In Laravel</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Mon, 10 Apr 2023 10:53:36 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/collection-in-laravel-1nb9</link>
      <guid>https://dev.to/codeofaccuracy/collection-in-laravel-1nb9</guid>
      <description>&lt;p&gt;A collection is a robust data structure that allows developers to work with arrays of data more easily and efficiently. It provides an object-oriented approach to working with arrays and offers a wide range of methods that can be used to manipulate, filter, sort, and transform data.&lt;/p&gt;

&lt;p&gt;Here's an example of how to create a collection in Laravel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$collection = collect(['apple', 'orange', 'banana', 'kiwi']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have created a collection of fruits. Now we can use various methods to work with this collection. For example, we can use the &lt;code&gt;filter&lt;/code&gt; method to filter out all the fruits that start with the letter &lt;code&gt;a&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$filtered = $collection-&amp;gt;filter(function ($value, $key) {
    return Str::startsWith($value, 'a');
});

// Output: ['apple']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have used the &lt;code&gt;filter&lt;/code&gt; method to create a new collection that only contains the fruit &lt;code&gt;apple&lt;/code&gt;, which is the only fruit that starts with the letter &lt;code&gt;a&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can also use the &lt;code&gt;sort&lt;/code&gt; method to sort the fruits alphabetically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$sorted = $collection-&amp;gt;sort();

// Output: ['apple', 'banana', 'kiwi', 'orange']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have used the &lt;code&gt;sort&lt;/code&gt; method to create a new collection that contains the fruits sorted alphabetically.&lt;/p&gt;

&lt;p&gt;One of the main benefits of collections in Laravel is the ability to chain methods together, allowing developers to perform multiple operations on a collection in a single line of code. Here's an example of how we can create a collection of users and filter them by age and then sort them by name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$users = collect([
    ['name' =&amp;gt; 'John', 'age' =&amp;gt; 30],
    ['name' =&amp;gt; 'Jane', 'age' =&amp;gt; 25],
    ['name' =&amp;gt; 'Bob', 'age' =&amp;gt; 35],
    ['name' =&amp;gt; 'Sarah', 'age' =&amp;gt; 28]
]);

$filteredUsers = $users
    -&amp;gt;where('age', '&amp;gt;', 25)
    -&amp;gt;sortBy('name');

// Output: [['name' =&amp;gt; 'Jane', 'age' =&amp;gt; 25], ['name' =&amp;gt; 'John', 'age' =&amp;gt; 30], ['name' =&amp;gt; 'Sarah', 'age' =&amp;gt; 28], ['name' =&amp;gt; 'Bob', 'age' =&amp;gt; 35]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have created a collection of &lt;code&gt;users&lt;/code&gt; with their &lt;code&gt;names&lt;/code&gt; and &lt;code&gt;ages&lt;/code&gt;. We then used the &lt;code&gt;where&lt;/code&gt; method to &lt;code&gt;filter&lt;/code&gt; the collection, only returning users who are older than 25. Finally, we used the &lt;code&gt;sortBy&lt;/code&gt; method to sort the filtered collection by name.&lt;/p&gt;

&lt;p&gt;Another useful method of collections in Laravel is the &lt;code&gt;map&lt;/code&gt; method. This method allows developers to transform the values in a collection by applying a callback function to each item in the collection. Here's an example of how we can use the map method to transform a collection of users into a collection of their full names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$users = collect([
    ['first_name' =&amp;gt; 'John', 'last_name' =&amp;gt; 'Doe'],
    ['first_name' =&amp;gt; 'Jane', 'last_name' =&amp;gt; 'Smith'],
    ['first_name' =&amp;gt; 'Bob', 'last_name' =&amp;gt; 'Johnson']
]);

$fullNames = $users-&amp;gt;map(function ($user) {
    return $user['first_name'] . ' ' . $user['last_name'];
});

// Output: ['John Doe', 'Jane Smith', 'Bob Johnson']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have used the &lt;code&gt;map&lt;/code&gt; method to create a new collection of full names by concatenating the first name and last name of each user in the original collection.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>collection</category>
      <category>php</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Primitive &amp; Non-Primitive Data Types</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Wed, 05 Apr 2023 11:16:25 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/primitive-non-primitive-data-types-1ghf</link>
      <guid>https://dev.to/codeofaccuracy/primitive-non-primitive-data-types-1ghf</guid>
      <description>&lt;p&gt;In JavaScript, data types can be broadly classified into two categories: &lt;code&gt;primitive&lt;/code&gt; and &lt;code&gt;non-primitive&lt;/code&gt; data types. Understanding these data types is crucial for writing effective and efficient code. In this article, we will explore &lt;code&gt;primitive&lt;/code&gt; and &lt;code&gt;non-primitive&lt;/code&gt; data types in JavaScript, along with examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primitive Data Types&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Primitive data types in JavaScript are simple data types that are not objects and do not have methods. They are immutable, which means that their values cannot be changed once they are created. There are six primitive data types in JavaScript.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;1. String:&lt;/strong&gt; A string is a collection of characters that are enclosed within single or double quotes. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = 'John Doe';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Number:&lt;/strong&gt; A number is a numerical value, which can be either positive, negative, or with decimal points. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age = 25;
let salary = 50000.50;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Boolean:&lt;/strong&gt; A boolean data type can have only two values - true or false. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let isMarried = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Null:&lt;/strong&gt; Null represents a null or empty value. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let address = null;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Undefined:&lt;/strong&gt; Undefined represents a variable that has not been assigned a value. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let gender;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Symbol:&lt;/strong&gt; A symbol is a unique and immutable data type that is used to identify object properties. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mySymbol = Symbol('mySymbol');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Non-Primitive Data Types&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Non-primitive data types in JavaScript are complex data types that are objects and can have methods. They are mutable, which means that their values can be changed. There are three non-primitive data types in JavaScript:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;1. Object:&lt;/strong&gt; An object is a collection of key-value pairs, where the key is a string and the value can be any data type. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
  name: 'John Doe',
  age: 25,
  isMarried: true
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Array:&lt;/strong&gt; An array is a collection of elements, which can be of any data type. The elements are indexed and can be accessed using the index number. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Function:&lt;/strong&gt; A function is a block of code that can be invoked or called to perform a specific task. It can accept parameters and return a value. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addNumbers(num1, num2) {
  return num1 + num2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>codeofaccuracy</category>
    </item>
    <item>
      <title>Laravel Job/Queue</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Tue, 28 Mar 2023 11:17:09 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/laravel-jobqueue-2f1p</link>
      <guid>https://dev.to/codeofaccuracy/laravel-jobqueue-2f1p</guid>
      <description>&lt;p&gt;Laravel provides a powerful &lt;code&gt;job and queue&lt;/code&gt; system that allows you to execute time-consuming tasks &lt;code&gt;asynchronously&lt;/code&gt; in the background, freeing up your application to handle other requests. Jobs represent individual units of work that can be executed independently, and queues are used to organize and prioritize jobs.&lt;/p&gt;

&lt;p&gt;Here are the basic steps involved in using Laravel's job and queue system:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a Job&lt;/strong&gt;&lt;br&gt;
To create a job in Laravel, you can use the &lt;code&gt;php artisan make:job&lt;/code&gt; command. This will create a new PHP class file in the &lt;code&gt;app/Jobs&lt;/code&gt; directory, which represents the job.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;You can then define the &lt;code&gt;handle&lt;/code&gt; method in the job class, which contains the logic for the job. This method is executed when the job is dispatched and processed by the queue worker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function handle()
{
    // Send email logic here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Dispatch the Job&lt;/strong&gt;&lt;br&gt;
To dispatch a job in Laravel, you can use the dispatch function. This function takes a job instance as its argument and adds the job to the queue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SendEmailJob::dispatch();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also chain additional methods to the dispatch function to configure the job, such as specifying a delay or a specific queue to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SendEmailJob::dispatch()-&amp;gt;delay(now()-&amp;gt;addMinutes(10))-&amp;gt;onQueue('emails');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Process the Queue&lt;/strong&gt;&lt;br&gt;
To process the queue in Laravel, you need to start the queue worker using the &lt;code&gt;php artisan queue:work&lt;/code&gt; command. This command starts a long-running PHP process that continuously polls the queue for new jobs to process.&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 queue:work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The queue worker executes each job by calling its handle method, and then marks the job as completed. If an error occurs while processing a job, the worker will retry the job a certain number of times before moving it to the failed job queue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Laravel's job and queue system is a powerful feature that can greatly improve the performance and scalability of your applications. By executing time-consuming tasks asynchronously in the background, your application can handle more requests and respond more quickly to users. With just a few simple steps, you can create, dispatch, process, and monitor jobs in Laravel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_Github : Practical for Job/Queue : _&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/codeofaccuracy/laravel-job-queue"&gt;https://github.com/codeofaccuracy/laravel-job-queue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You can just follow the README.md file.&lt;/p&gt;

&lt;p&gt;Thanks for Reading.....&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>beginners</category>
      <category>jobs</category>
      <category>queue</category>
    </item>
    <item>
      <title>Collection VS Array</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Mon, 27 Mar 2023 13:10:12 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/collection-vs-array-2e0n</link>
      <guid>https://dev.to/codeofaccuracy/collection-vs-array-2e0n</guid>
      <description>&lt;p&gt;&lt;strong&gt;Collection VS Array &amp;amp; When To Use Which&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Laravel, Arrays and Collections are both used for storing and manipulating sets of data. However, they have some key differences in terms of functionality and performance. Here's a brief overview of arrays and collections in Laravel, along with some examples of when to use each one:&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;An array is a basic data structure that stores a set of values, indexed by a numeric key.&lt;/li&gt;
&lt;li&gt;Laravel provides a number of helper functions for working with arrays, including &lt;code&gt;array_map()&lt;/code&gt;, &lt;code&gt;array_filter()&lt;/code&gt;, and &lt;code&gt;array_reduce()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Arrays are generally faster and use less memory than collections, especially for small datasets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use&lt;/strong&gt;: &lt;br&gt;
              Arrays are a good choice when you have a simple dataset that you need to iterate over quickly. For example, if you're working with a small set of numeric values, you might use an array to store them.&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;$numbers = [1, 2, 3, 4, 5];
$filtered_numbers = array_filter($numbers, function($num) {
    return $num % 2 == 0;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;A collection is an object-oriented version of an array, with additional methods and functionality for working with the data.&lt;/li&gt;
&lt;li&gt;Laravel's collection class provides a wide range of helper methods for filtering, transforming, and sorting data, such as &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;sortBy()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Collections are generally slower and use more memory than arrays, especially for large datasets. However, they provide more functionality and flexibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;br&gt;
              Collections are a good choice when you need to work with more complex datasets that require filtering, sorting, or transformation. For example, if you're working with a collection of database records, you might use a collection to filter the records by certain criteria and then sort them by date. Collections are also useful when you need to chain multiple operations together, as the fluent interface makes it easy to do so.&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;$users = App\Models\User::all();
$admins = $users-&amp;gt;filter(function ($user) {
    return $user-&amp;gt;isAdmin();
});
$names = $admins-&amp;gt;map(function ($user) {
    return $user-&amp;gt;name;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>array</category>
      <category>beginners</category>
      <category>collection</category>
    </item>
    <item>
      <title>HAVING Clause In MySQL</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Mon, 27 Mar 2023 11:11:00 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/having-clause-in-mysql-2b79</link>
      <guid>https://dev.to/codeofaccuracy/having-clause-in-mysql-2b79</guid>
      <description>&lt;p&gt;The &lt;code&gt;HAVING&lt;/code&gt; clause is used in MySQL to filter the results of a query based on a condition that involves an aggregate function. This clause is used after the &lt;code&gt;GROUP BY&lt;/code&gt; clause to filter the grouped data based on the result of the aggregate function.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column1, column2, aggregate_function(column_name)
FROM table_name
WHERE condition
GROUP BY column1, column2
HAVING aggregate_function(column_name) condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;HAVING&lt;/code&gt; clause is similar to the &lt;code&gt;WHERE&lt;/code&gt; clause, but the &lt;code&gt;WHERE&lt;/code&gt; clause filters the rows before the data is grouped, while the &lt;code&gt;HAVING&lt;/code&gt; clause filters the groups after the data is grouped.&lt;/p&gt;

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

&lt;p&gt;Let's consider the following table named &lt;code&gt;orders&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;OrderID&lt;/th&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;OrderDate&lt;/th&gt;
&lt;th&gt;TotalAmount&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2022-01-01&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2022-01-02&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2022-01-03&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2022-01-04&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2022-01-05&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If we want to find the total amount of orders for each customer and only show the results for customers who have ordered more than 300 dollars, we can use the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT CustomerID, SUM(TotalAmount) as Total
FROM orders
GROUP BY CustomerID
HAVING SUM(TotalAmount) &amp;gt; 300;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will be:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;CustomerID&lt;/th&gt;
&lt;th&gt;Total&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;600&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As you can see, the &lt;code&gt;HAVING&lt;/code&gt; clause is used to filter the result set based on the aggregate function &lt;code&gt;SUM(TotalAmount)&lt;/code&gt;, which calculates the total amount of orders for each customer. The condition &lt;code&gt;SUM(TotalAmount) &amp;gt; 300&lt;/code&gt; filters out the customers who have ordered less than 300 dollars.&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>beginners</category>
      <category>havingclaus</category>
      <category>programming</category>
    </item>
    <item>
      <title>MySQL joins</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Mon, 27 Mar 2023 10:18:20 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/tesr-4m8e</link>
      <guid>https://dev.to/codeofaccuracy/tesr-4m8e</guid>
      <description>&lt;p&gt;MySQL joins are used to combine rows from two or more tables based on a related column between them. Joins are essential for retrieving data from multiple tables in a single query. In this article, we will discuss different types of joins in MySQL with examples.&lt;/p&gt;

&lt;p&gt;Types of Joins in MySQL:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. INNER JOIN&lt;/strong&gt;: An inner join returns only the &lt;code&gt;matching rows&lt;/code&gt; from both tables. It returns the rows that have matching values in both tables.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

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

&lt;/div&gt;



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

&lt;p&gt;Consider two tables &lt;code&gt;employees&lt;/code&gt; and &lt;code&gt;departments&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Table: &lt;code&gt;employees&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;emp_id&lt;/th&gt;
&lt;th&gt;emp_name&lt;/th&gt;
&lt;th&gt;emp_salary&lt;/th&gt;
&lt;th&gt;dept_id&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;Smith&lt;/td&gt;
&lt;td&gt;60000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;55000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;104&lt;/td&gt;
&lt;td&gt;Joe&lt;/td&gt;
&lt;td&gt;45000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Table: &lt;code&gt;departments&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;dept_id&lt;/th&gt;
&lt;th&gt;dept_name&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To join these tables based on &lt;code&gt;dept_id&lt;/code&gt; column:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.emp_name, departments.dept_name
FROM employees
INNER JOIN departments
ON employees.dept_id = departments.dept_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;emp_name&lt;/th&gt;
&lt;th&gt;dept_name&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Smith&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Joe&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. LEFT JOIN&lt;/strong&gt;: A left join returns all the rows from the left table and matching rows from the right table. If there is no matching row in the right table, it returns null.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Consider two tables &lt;code&gt;students&lt;/code&gt; and &lt;code&gt;grades&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Table: &lt;code&gt;students&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;student_id&lt;/th&gt;
&lt;th&gt;student_name&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;Smith&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;104&lt;/td&gt;
&lt;td&gt;Joe&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Table: &lt;code&gt;grades&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;student_id&lt;/th&gt;
&lt;th&gt;grade&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;104&lt;/td&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To join these tables based on &lt;code&gt;student_id&lt;/code&gt; column:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT students.student_name, grades.grade
FROM students
LEFT JOIN grades
ON students.student_id = grades.student_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;student_name&lt;/th&gt;
&lt;th&gt;grade&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Smith&lt;/td&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Joe&lt;/td&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. RIGHT JOIN&lt;/strong&gt;: A right join returns all the rows from the right table and matching rows from the left table. If there is no matching row in the left table, it returns null.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Consider two tables &lt;code&gt;employees&lt;/code&gt; and &lt;code&gt;departments&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Table: &lt;code&gt;employees&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;emp_id&lt;/th&gt;
&lt;th&gt;emp_name&lt;/th&gt;
&lt;th&gt;emp_salary&lt;/th&gt;
&lt;th&gt;dept_id&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;50000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;Smith&lt;/td&gt;
&lt;td&gt;60000&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;103&lt;/td&gt;
&lt;td&gt;Mary&lt;/td&gt;
&lt;td&gt;55000&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>mysql</category>
      <category>joins</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>View In MySQL</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Sat, 25 Mar 2023 11:57:04 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/view-in-mysql-404m</link>
      <guid>https://dev.to/codeofaccuracy/view-in-mysql-404m</guid>
      <description>&lt;p&gt;A view is a virtual table that is based on the result of a &lt;code&gt;SELECT&lt;/code&gt; statement. Views are used to simplify complex queries by providing a way to create a logical representation of the data in a database. Once a view is created, it can be used like any other table in the database.&lt;/p&gt;

&lt;p&gt;To create a view in MySQL, you can use the &lt;code&gt;CREATE VIEW&lt;/code&gt; statement. Here's the basic syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;view_name&lt;/code&gt;is the name you want to give to your view, &lt;code&gt;table_name&lt;/code&gt; is the name of the table you want to base your view on, and &lt;code&gt;column1&lt;/code&gt;, &lt;code&gt;column2&lt;/code&gt;, etc. are the columns you want to include in your view. You can also include a &lt;code&gt;WHERE&lt;/code&gt; clause to filter the data that's included in your view.&lt;/p&gt;

&lt;p&gt;For example, let's say you have a table called &lt;code&gt;customers&lt;/code&gt; with columns &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, and &lt;code&gt;email&lt;/code&gt;. You could create a view that includes only the &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; columns like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE VIEW customer_names AS
SELECT id, name
FROM customers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you've created a view, you can use it in your queries just like you would any other table. For example, you could run a query to select all the &lt;code&gt;customers&lt;/code&gt; from the &lt;code&gt;customer_names&lt;/code&gt; view like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM customer_names;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would return a result set with just the &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; columns from the &lt;code&gt;customers&lt;/code&gt; table.&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>view</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Indexing In MySQL</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Sat, 25 Mar 2023 11:46:51 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/indexing-in-mysql-29e7</link>
      <guid>https://dev.to/codeofaccuracy/indexing-in-mysql-29e7</guid>
      <description>&lt;p&gt;Indexing in MySQL is a technique used to optimize the database performance by creating a data structure that provides &lt;code&gt;fast access to the rows in a table&lt;/code&gt;. An index is essentially a data structure that is used to &lt;code&gt;speed up&lt;/code&gt; the retrieval of data from a table. It works by creating a separate structure that contains a subset of the data in the table, along with pointers to the corresponding rows in the table.&lt;/p&gt;

&lt;p&gt;An index is similar to an index in a &lt;code&gt;book or a library&lt;/code&gt;. It helps you find the data you need more quickly by providing a map to the data. Without an &lt;code&gt;index&lt;/code&gt;, MySQL would have to search through every row in a table to find the data you need, which can be a &lt;code&gt;time-consuming and resource-intensive process&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To create an index in MySQL, you can use the &lt;code&gt;CREATE INDEX statement&lt;/code&gt;. For example, let's say we have a table called &lt;code&gt;employees&lt;/code&gt; with columns for &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, and &lt;code&gt;department&lt;/code&gt;. We can create an index on the &lt;code&gt;name&lt;/code&gt; column using the following SQL statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE INDEX idx_name ON employees (name);

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

&lt;/div&gt;



&lt;p&gt;This statement creates an index called &lt;code&gt;idx_name&lt;/code&gt; on the &lt;code&gt;name&lt;/code&gt; column of the &lt;code&gt;employees&lt;/code&gt; table. The index will contain a subset of the data in the &lt;code&gt;name&lt;/code&gt; column, along with pointers to the corresponding rows in the table.&lt;/p&gt;

&lt;p&gt;Once the index is created, MySQL will use it to speed up queries that involve the &lt;code&gt;name&lt;/code&gt; column. For example, if we want to find all employees with the name &lt;code&gt;John&lt;/code&gt;, we can use the following SQL statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM employees WHERE name = 'John';

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

&lt;/div&gt;



&lt;p&gt;It's important to note that while indexing can greatly improve the performance of your database, it can also have some downsides. Indexes take up space on disk and in memory, so creating too many indexes can have a negative impact on performance. Additionally, indexes need to be updated every time the table they're associated with is updated, which can also impact performance.&lt;/p&gt;

&lt;p&gt;In conclusion, indexing in MySQL is a powerful technique that can greatly improve the performance of your database. By creating an index on a column or set of columns, you can speed up queries and reduce the amount of time it takes to retrieve data from your tables. However, it's important to use indexes judiciously and be mindful of their impact on performance.&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>indexing</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Lazy Loading &amp; Eager Loading</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Sat, 25 Mar 2023 10:45:11 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/lazy-loading-eager-loading-2lol</link>
      <guid>https://dev.to/codeofaccuracy/lazy-loading-eager-loading-2lol</guid>
      <description>&lt;p&gt;In Laravel, &lt;code&gt;lazy&lt;/code&gt; loading and &lt;code&gt;eager&lt;/code&gt; loading are two techniques for fetching related data from a database. Understanding the differences between these two techniques can help developers &lt;code&gt;optimize&lt;/code&gt; their application's &lt;code&gt;performance&lt;/code&gt; and prevent unnecessary database queries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Eager Loading&lt;/strong&gt;&lt;br&gt;
        Eager loading is a technique that allows developers to load related data along with the main model. It is best used when a developer knows that they will need to access the related data and wants to minimize the number of database queries needed. &lt;code&gt;Eager&lt;/code&gt; loading is achieved using the &lt;code&gt;with&lt;/code&gt; method in Laravel.&lt;/p&gt;

&lt;p&gt;For example, suppose we have a &lt;code&gt;Post&lt;/code&gt; model that has many &lt;code&gt;Comments&lt;/code&gt; and we want to display all posts and their comments on a page. Without eager loading, we would need to perform a separate database query for each post to retrieve its comments. With eager loading, we can use the &lt;code&gt;with&lt;/code&gt; method to load all comments along with the posts in a &lt;code&gt;single query&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$posts = Post::with('comments')-&amp;gt;get();

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Lazy Loading&lt;/strong&gt;&lt;br&gt;
       Lazy loading, on the other hand, is a technique that delays the loading of related data until it is actually needed. It is best used when a developer is unsure whether they will need to access the related data and wants to minimize the initial database queries. In Laravel, lazy loading is achieved using &lt;code&gt;lazy relationships&lt;/code&gt; or by accessing the related data through a &lt;code&gt;magic&lt;/code&gt; property on the model.&lt;/p&gt;

&lt;p&gt;The n+1 problem occurs in lazy loading when you load related data in a loop. For example, if you have a view that displays a list of Users and the number of Posts each User has.&lt;/p&gt;

&lt;p&gt;For example, suppose we have a &lt;code&gt;User&lt;/code&gt; model that has many &lt;code&gt;Posts&lt;/code&gt; and we want to display all users and their posts on a page. With lazy loading, we would retrieve all users first, and then use lazy loading to retrieve each user's posts only when they are needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$users = User::all();

foreach ($users as $user) {
    foreach ($user-&amp;gt;posts as $post) {
        // do something with the post
    }
}

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

&lt;/div&gt;



&lt;p&gt;In this example, lazy loading is used to retrieve each user's posts only when they are needed, which minimizes the number of initial database queries.&lt;/p&gt;

&lt;p&gt;To solve the n+1 problem, you can use eager loading instead of lazy loading. You can modify your query to fetch all the related Posts at once.&lt;/p&gt;

</description>
      <category>lazyeagerloading</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is Override And Extensions</title>
      <dc:creator>Code Of Accuracy</dc:creator>
      <pubDate>Fri, 24 Mar 2023 07:07:34 +0000</pubDate>
      <link>https://dev.to/codeofaccuracy/what-is-override-and-extensions-apm</link>
      <guid>https://dev.to/codeofaccuracy/what-is-override-and-extensions-apm</guid>
      <description>&lt;p&gt;In object-oriented programming, overriding and extensions are common concepts that allow developers to modify or enhance the behavior of existing classes or methods. In this article, we'll explore these concepts in the context of PHP, with examples to demonstrate their usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Overriding in PHP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Overriding is the process of redefining a method in a subclass that was already defined in the parent class. This allows the subclass to provide its own implementation of the method, which may be different from the parent class.&lt;/p&gt;

&lt;p&gt;Consider the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal {
  public function makeSound() {
    echo "The animal makes a sound";
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Cat extends Animal {
  public function makeSound() {
    echo "Meow!";
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$cat = new Cat();
$cat-&amp;gt;makeSound(); // Outputs "Meow!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a base class &lt;code&gt;Animal&lt;/code&gt; that defines a &lt;code&gt;makeSound()&lt;/code&gt; method. The &lt;code&gt;Cat&lt;/code&gt; class extends &lt;code&gt;Animal&lt;/code&gt; and &lt;code&gt;overrides&lt;/code&gt; the &lt;code&gt;makeSound()&lt;/code&gt; method with its own implementation that outputs &lt;code&gt;Meow!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When we create an instance of &lt;code&gt;Cat&lt;/code&gt; and call &lt;code&gt;makeSound()&lt;/code&gt;, the overridden implementation in &lt;code&gt;Cat&lt;/code&gt; is executed instead of the one in &lt;code&gt;Animal&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Extensions in PHP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Extensions, also known as &lt;code&gt;method chaining&lt;/code&gt;, is a technique that allows developers to add functionality to an object by chaining method calls together. This can make code more concise and easier to read.&lt;/p&gt;

&lt;p&gt;Consider the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
  private $model;

  public function setModel($model) {
    $this-&amp;gt;model = $model;
    return $this;
  }

  public function setColor($color) {
    $this-&amp;gt;color = $color;
    return $this;
  }

  public function setYear($year) {
    $this-&amp;gt;year = $year;
    return $this;
  }
}

$car = new Car();
$car-&amp;gt;setModel("Tesla")
    -&amp;gt;setColor("Red")
    -&amp;gt;setYear(2022);

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

&lt;/div&gt;



&lt;p&gt;In this example, we have a &lt;code&gt;Car&lt;/code&gt; class with three setter methods that set the &lt;code&gt;model, color, and year&lt;/code&gt; properties of the car. Each method returns &lt;code&gt;$this&lt;/code&gt;, allowing the methods to be chained together.&lt;/p&gt;

&lt;p&gt;When we create a new instance of &lt;code&gt;Car&lt;/code&gt; and call the setter methods, we can chain them together to set all three properties in a single line of code.&lt;/p&gt;

&lt;p&gt;In PHP, &lt;code&gt;overriding&lt;/code&gt; and &lt;code&gt;extensions&lt;/code&gt; are powerful techniques that allow developers to modify or enhance the behavior of existing classes or methods. By understanding these concepts and using them effectively, you can write more flexible and maintainable code.&lt;/p&gt;

</description>
      <category>overridin</category>
      <category>laravel</category>
      <category>php</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
