<?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: Akhilesh Gupta</title>
    <description>The latest articles on DEV Community by Akhilesh Gupta (@akhilh2o).</description>
    <link>https://dev.to/akhilh2o</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%2F434785%2F5ab66bc5-e22d-4dc7-9ffb-bf6670417246.jpg</url>
      <title>DEV Community: Akhilesh Gupta</title>
      <link>https://dev.to/akhilh2o</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akhilh2o"/>
    <language>en</language>
    <item>
      <title>Laravel: Avoid N+1 queries in API resources</title>
      <dc:creator>Akhilesh Gupta</dc:creator>
      <pubDate>Wed, 25 Oct 2023 07:43:59 +0000</pubDate>
      <link>https://dev.to/akhilh2o/laravel-avoid-n1-queries-in-api-resources-i9e</link>
      <guid>https://dev.to/akhilh2o/laravel-avoid-n1-queries-in-api-resources-i9e</guid>
      <description>&lt;p&gt;You can avoid N+1 queries in API resources by using the &lt;code&gt;whenLoaded()&lt;/code&gt; method. This will only append the department if it’s already loaded in the Employee model. Without &lt;code&gt;whenLoaded()&lt;/code&gt; there is always a query for the department.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class EmployeeResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'id' =&amp;gt; $this-&amp;gt;uuid,
            'fullName' =&amp;gt; $this-&amp;gt;full_name,
            'email' =&amp;gt; $this-&amp;gt;email,
            'jobTitle' =&amp;gt; $this-&amp;gt;job_title,
            'department' =&amp;gt; DepartmentResource::make($this-&amp;gt;whenLoaded('department')),
        ];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>programming</category>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel: Conditional Relationship Counts on API Resources</title>
      <dc:creator>Akhilesh Gupta</dc:creator>
      <pubDate>Wed, 25 Oct 2023 07:35:33 +0000</pubDate>
      <link>https://dev.to/akhilh2o/laravel-conditional-relationship-counts-on-api-resources-489e</link>
      <guid>https://dev.to/akhilh2o/laravel-conditional-relationship-counts-on-api-resources-489e</guid>
      <description>&lt;p&gt;You may conditionally include the count of a relationship in your resource response by using the whenCounted method. By doing so, the attribute is not included if the relationships' count is missing.&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 toArray($request)
    {
        return [
            'id' =&amp;gt; $this-&amp;gt;id,
            'name' =&amp;gt; $this-&amp;gt;name,
            'email' =&amp;gt; $this-&amp;gt;email,
            'posts_count' =&amp;gt; $this-&amp;gt;whenCounted('posts'),
            'created_at' =&amp;gt; $this-&amp;gt;created_at,
            'updated_at' =&amp;gt; $this-&amp;gt;updated_at,
        ];
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>programming</category>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel: API Resources: With or Without "data"?</title>
      <dc:creator>Akhilesh Gupta</dc:creator>
      <pubDate>Wed, 25 Oct 2023 07:22:24 +0000</pubDate>
      <link>https://dev.to/akhilh2o/laravel-api-resources-with-or-without-data-5dkn</link>
      <guid>https://dev.to/akhilh2o/laravel-api-resources-with-or-without-data-5dkn</guid>
      <description>&lt;p&gt;If you use Eloquent API Resources to return data, they will be automatically wrapped in 'data'. If you want to remove it, add &lt;strong&gt;JsonResource::withoutWrapping();&lt;/strong&gt; in &lt;strong&gt;app/Providers/AppServiceProvider.php.&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;class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        JsonResource::withoutWrapping();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>php</category>
      <category>mvc</category>
      <category>eloquent</category>
    </item>
    <item>
      <title>How to useState in React?</title>
      <dc:creator>Akhilesh Gupta</dc:creator>
      <pubDate>Sat, 10 Oct 2020 20:41:59 +0000</pubDate>
      <link>https://dev.to/akhilh2o/how-to-usestate-in-react-enm</link>
      <guid>https://dev.to/akhilh2o/how-to-usestate-in-react-enm</guid>
      <description>&lt;p&gt;hey!&lt;/p&gt;

&lt;p&gt;As a newbie, when I started react JS, I don't know where to start today I'm learning how use useState hook in react.&lt;/p&gt;

&lt;p&gt;newbie code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";
import "./App.css";

function App() {

  const [activated, setActivated] = useState(false);
  return (

    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h2&amp;gt;React useState Hook&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;I am {activated ? "on" : "off"}.&amp;lt;/p&amp;gt;
      &amp;lt;button type="button"
        className="main-button"
        onClick={() =&amp;gt; setActivated(activated ? false : true)}&amp;gt; 
       {activated ? "Deactivate Me !" : "Activate Me !"}!&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;

  );

}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>frontend</category>
      <category>usestate</category>
    </item>
  </channel>
</rss>
