<?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: JohnDivam</title>
    <description>The latest articles on DEV Community by JohnDivam (@johndivam).</description>
    <link>https://dev.to/johndivam</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%2F1117777%2F84c084ba-ea49-4650-abdf-c74df4f4989f.png</url>
      <title>DEV Community: JohnDivam</title>
      <link>https://dev.to/johndivam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johndivam"/>
    <language>en</language>
    <item>
      <title>Filament: Hide Submit and Cancel Buttons in wizard</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Tue, 28 Oct 2025 10:19:50 +0000</pubDate>
      <link>https://dev.to/johndivam/filament-hide-submit-and-cancel-buttons-in-wizard-2bi7</link>
      <guid>https://dev.to/johndivam/filament-hide-submit-and-cancel-buttons-in-wizard-2bi7</guid>
      <description>&lt;p&gt;Override the submitAction dynamically in the Page class&lt;br&gt;
If you’re in a CreatePage or EditPage, you can control visibility 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;class CreatePage extends CreateRecord
{
    protected static string $resource = PageResource::class;

    //add this 
    public function getFormActions(): array
    {
        return [

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

&lt;/div&gt;



&lt;p&gt;And in your PageForm :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wizard::make([
...
])
 -&amp;gt;submitAction(view('filament.submit-button'))

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

&lt;/div&gt;



&lt;p&gt;// in resources\views\filament\submit-button.blade.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div 
    x-data
    x-transition
&amp;gt;
    &amp;lt;x-filament::button
        type="submit"
        color="primary"
        class="fi-btn"
    &amp;gt;
        Submit
    &amp;lt;/x-filament::button&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



</description>
      <category>php</category>
      <category>laravel</category>
      <category>filament</category>
    </item>
    <item>
      <title>Laravel app was slow. Here's how I fixed it</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Fri, 17 Oct 2025 14:25:08 +0000</pubDate>
      <link>https://dev.to/johndivam/laravel-app-was-slow-heres-how-i-fixed-it-19hj</link>
      <guid>https://dev.to/johndivam/laravel-app-was-slow-heres-how-i-fixed-it-19hj</guid>
      <description>&lt;p&gt;Imagine fetching 100 users, each with related posts and comments.&lt;br&gt;
Without optimization, your app might execute 1000+ queries just to load a single page!&lt;br&gt;
The result? Slow performance, wasted resources, and frustrated users.&lt;br&gt;
Let’s fix it step by step : &lt;/p&gt;

&lt;p&gt;1️⃣** Eager Loading -&amp;gt;with()**&lt;br&gt;
Instead of making one query per related record, load relationships in advance.&lt;/p&gt;

&lt;p&gt;Before:&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();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&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::with('posts', 'comments')-&amp;gt;get(); //Faster. Cleaner. Efficient.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2️⃣ &lt;strong&gt;Database Indexing&lt;/strong&gt;&lt;br&gt;
Add indexes to columns you frequently query or use in WHERE, JOIN, and ORDER BY clauses.&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;CREATE INDEX idx_user_email ON users(email); //Query time improved from 800ms → 50ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3️⃣ &lt;strong&gt;Query Caching (Laravel Cache)&lt;/strong&gt;&lt;br&gt;
Cache repeated queries or expensive operations using Laravel’s built-in caching.&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 = Cache::remember('users_with_posts', 60, function() {
    return User::with('posts')-&amp;gt;get();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4️⃣ &lt;strong&gt;Lazy Loading Assets (Images, Videos, etc.)&lt;/strong&gt;&lt;br&gt;
Optimize your frontend performance by loading assets only when they’re visible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="image.jpg" loading="lazy" alt="User profile"&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Faster page rendering and lower initial load times.&lt;/p&gt;

&lt;p&gt;5️⃣ &lt;strong&gt;Optimize Select Queries (Avoid SELECT *)&lt;/strong&gt;&lt;br&gt;
Fetching unnecessary columns bloats your response and slows queries.&lt;/p&gt;

&lt;p&gt;Before:&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::with('posts')-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&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::select('id', 'name', 'email')
             -&amp;gt;with('posts:id,user_id,title')
             -&amp;gt;get(); //Only the data you need — smaller payloads, faster delivery.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
Performance optimization isn’t a one-time task — it’s an ongoing discipline.&lt;br&gt;
By combining eager loading, indexing, caching, and smart query design, you can turn a slow, bloated app into a lightning-fast experience ⚡.&lt;/p&gt;

</description>
      <category>performance</category>
      <category>laravel</category>
      <category>php</category>
      <category>database</category>
    </item>
    <item>
      <title>Is Laravel the Best PHP Framework in 2025</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Fri, 17 Oct 2025 14:12:53 +0000</pubDate>
      <link>https://dev.to/johndivam/is-laravel-the-best-php-framework-in-2025-53ch</link>
      <guid>https://dev.to/johndivam/is-laravel-the-best-php-framework-in-2025-53ch</guid>
      <description>&lt;p&gt;While new frameworks pop up every year, Laravel continues to stand tall as the go-to choice for developers worldwide. Here’s why it remains unbeatable: &lt;/p&gt;

&lt;p&gt;1️⃣ Elegant, Readable Syntax&lt;br&gt;
Laravel’s syntax is poetry in code — clean, expressive, and a joy to work with. Writing Laravel feels natural, like speaking fluent English. It’s not just beautiful — it’s maintainable and developer-friendly.&lt;/p&gt;

&lt;p&gt;2️⃣ A Massive, Integrated Ecosystem&lt;br&gt;
Forge – effortless server management and deployment&lt;br&gt;
Vapor – seamless serverless scaling on AWS&lt;br&gt;
Nova – powerful, elegant admin panels&lt;br&gt;
Horizon – advanced queue monitoring and control&lt;br&gt;
Everything you need to build, deploy, and scale — all within reach.&lt;/p&gt;

&lt;p&gt;3️⃣ A Thriving Global Community&lt;br&gt;
Get stuck? You’re never alone. Thousands of Laravel developers are ready to help.&lt;br&gt;
From Laracasts tutorials to active Discord servers, forums, and GitHub discussions, support is always just a message away.&lt;/p&gt;

&lt;p&gt;4️⃣ Packed with Modern Features&lt;br&gt;
Laravel brings all the essentials of modern web development — no extra setup required:&lt;br&gt;
✅ Built-in authentication&lt;br&gt;
✅ Queue management&lt;br&gt;
✅ Real-time event broadcasting&lt;br&gt;
✅ Task scheduling&lt;br&gt;
✅ API resources and resourceful routing&lt;/p&gt;

&lt;p&gt;It’s modern, streamlined, and designed for productivity.&lt;/p&gt;

&lt;p&gt;5️⃣ Scales with Your Vision&lt;br&gt;
Whether you’re launching a small MVP or running an enterprise app serving millions, Laravel grows with you. Its architecture and ecosystem are built for performance and scalability. 💪&lt;/p&gt;

&lt;p&gt;6️⃣ Constantly Evolving&lt;br&gt;
Led by Taylor Otwell and an incredible open-source community, Laravel evolves rapidly. Expect frequent updates, new features, and rock-solid security patches — keeping your stack modern and secure.&lt;/p&gt;

&lt;p&gt;7️⃣ Job Market&lt;br&gt;
Laravel skills are in high demand. From startups to global companies, everyone’s hiring Laravel developers — and the opportunities just keep growing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Laravel isn’t just surviving the test of time — it’s defining the future of web development.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Groups in Filament v4</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Sat, 11 Oct 2025 10:56:30 +0000</pubDate>
      <link>https://dev.to/johndivam/groups-in-filament-v4-3m6k</link>
      <guid>https://dev.to/johndivam/groups-in-filament-v4-3m6k</guid>
      <description>&lt;p&gt;you can use it with any layout component. For example, you could use a Group component which has no styling associated with it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Filament\Schemas\Components\Section;


public static function configure(Schema $schema): Schema
    {
        return $schema
            -&amp;gt;components([
                Section::make()
                  -&amp;gt;schema([
                    TextInput::make('test1'),
                ])-&amp;gt;columnSpan(['lg' =&amp;gt; 2]),
                Section::make()
                  -&amp;gt;schema([
                    TextInput::make('test2'),
                ])-&amp;gt;columnSpan(['lg' =&amp;gt; 1]),
            ])-&amp;gt;columns(3);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsf1j17vw3ucws341qrei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsf1j17vw3ucws341qrei.png" alt=" " width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>filament</category>
      <category>php</category>
    </item>
    <item>
      <title>Filament: Form Select append extra option</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Sat, 11 Oct 2025 10:37:24 +0000</pubDate>
      <link>https://dev.to/johndivam/filament-form-select-append-extra-option-23f5</link>
      <guid>https://dev.to/johndivam/filament-form-select-append-extra-option-23f5</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Forms\Components\Select::make('employee_id')-&amp;gt;label('recipient')
                        -&amp;gt;options(function(){
                            return Employee::query()-&amp;gt;active()
                            -&amp;gt;pluck('name', 'id')
                            -&amp;gt;toBase() 
                            -&amp;gt;put('other', 'other') 
                            -&amp;gt;toArray();
                        })
                        -&amp;gt;reactive()
                        -&amp;gt;required(),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>filament</category>
    </item>
    <item>
      <title>Filament Repeater, total sum &amp; validate</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Sat, 27 Sep 2025 10:40:23 +0000</pubDate>
      <link>https://dev.to/johndivam/filament-repeater-total-sum-validate-254k</link>
      <guid>https://dev.to/johndivam/filament-repeater-total-sum-validate-254k</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Sum the values of all repeater rows&lt;/li&gt;
&lt;li&gt;Validate the total against a maximum&lt;/li&gt;
&lt;li&gt;Update another field automatically
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return $form-&amp;gt;schema([

    // This field will display the calculated total
    Forms\Components\TextInput::make('qnt_allocated')
       -&amp;gt;label('Total Quantity')
        -&amp;gt;required()
        -&amp;gt;numeric()
        -&amp;gt;suffix('Kg'),

    // Repeater of groups
    Forms\Components\Repeater::make('groups')
        -&amp;gt;label('groups:')
        -&amp;gt;relationship('groups')
        -&amp;gt;schema([
            Forms\Components\TextInput::make('quantity')
                -&amp;gt;label('group quantity')
                -&amp;gt;required()
                -&amp;gt;numeric()
                -&amp;gt;reactive()
                -&amp;gt;rules([
                    fn (Get $get): \Closure =&amp;gt; function (string $attribute, $value, \Closure $fail) use ($get) {
                        $total = collect($get('../../groups'))-&amp;gt;sum('quantity');
                        if ($total &amp;gt; 7000) {
                           $fail("Total quantity for all groups cannot exceed 7000 kg (Current total: {$total})");
                        }
                    },
                ])
                -&amp;gt;afterStateUpdated(function ($state, callable $get, callable $set) {
                    $total = collect($get('../../groups'))-&amp;gt;sum('quantity');
                    $set('../../qnt_allocated', $total);
                })
                -&amp;gt;suffix('Kg'),
        ])
]);

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

&lt;/div&gt;



</description>
      <category>filament</category>
      <category>laravel</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Filament How to redirect to list page after (create,update) using Trait</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Thu, 22 Aug 2024 11:51:59 +0000</pubDate>
      <link>https://dev.to/johndivam/filamtn-how-to-redirect-to-list-page-after-createupdate-using-trait-5b0i</link>
      <guid>https://dev.to/johndivam/filamtn-how-to-redirect-to-list-page-after-createupdate-using-trait-5b0i</guid>
      <description>&lt;p&gt;To redirect to the list page after creating or updating a resource in Filament v3, you can use a custom trait in your resource class . &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Custom Trait&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;&amp;lt;?php

namespace App\Traits;

trait RedirectIndex
{
    protected function getRedirectUrl(): string
    {
        return $this-&amp;gt;getResource()::getUrl('index');
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use the Trait in Your Filament Resource&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 CreateProduct extends CreateRecord
{
    protected static string $resource = ProductResource::class;

   //add trait in your CreateRecord or UpdateRecord
    use \App\Traits\RedirectIndex; 
}

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

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>filament</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel Filament: get resource table data by authenticated id</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Tue, 02 Jul 2024 11:06:22 +0000</pubDate>
      <link>https://dev.to/johndivam/laravel-filament-get-resource-table-data-by-authenticated-id-15j7</link>
      <guid>https://dev.to/johndivam/laravel-filament-get-resource-table-data-by-authenticated-id-15j7</guid>
      <description>&lt;p&gt;To restrict the display of resources in a Filament resource based on the user_id of the authenticated user, you can modify the getEloquentQuery() method in your Filament resource class. Here’s how you can do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public static function getEloquentQuery(): Builder{
        return parent::getEloquentQuery()-&amp;gt;where('user_id',auth()-&amp;gt;id());
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>filament</category>
      <category>webdev</category>
      <category>php</category>
    </item>
    <item>
      <title>Filament: add a confirmation password field in a form</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Wed, 26 Jun 2024 14:31:58 +0000</pubDate>
      <link>https://dev.to/johndivam/filament-to-add-a-confirmation-password-field-in-a-form-38kk</link>
      <guid>https://dev.to/johndivam/filament-to-add-a-confirmation-password-field-in-a-form-38kk</guid>
      <description>&lt;p&gt;To add a confirmation password field in a form, you typically want to ensure that the user correctly enters their password twice to prevent typos and ensure accuracy .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Forms\Components\TextInput::make('password')
                    -&amp;gt;password()
                    -&amp;gt;required()
                    -&amp;gt;maxLength(255),
 Forms\Components\TextInput::make('password_confirmation')
                    -&amp;gt;password()
                    -&amp;gt;required()
                    -&amp;gt;maxLength(255)
                    -&amp;gt;same('password')
                    -&amp;gt;label('Confirm Password'),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>filament</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel Scope to get locations nearest the user location</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Fri, 14 Jun 2024 19:55:03 +0000</pubDate>
      <link>https://dev.to/johndivam/laravel-scope-to-get-locations-nearest-the-user-location-2fk5</link>
      <guid>https://dev.to/johndivam/laravel-scope-to-get-locations-nearest-the-user-location-2fk5</guid>
      <description>&lt;p&gt;In many web applications, particularly those that involve mapping or location-based services, it is crucial to retrieve and display locations closest to a user's current position  . &lt;/p&gt;

&lt;p&gt;When dealing with geographical coordinates, calculating the distance between two points on the Earth's surface can be complex due to the spherical nature of the Earth. The Haversine formula is commonly used for this purpose. It calculates the distance between two points on a sphere given their longitudes and latitudes.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setting Up the Scope&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Farm extends Model
{

    public function scopeClosest($query, $lat, $long)
    {
        $distanceQuery = "
            ( 6371 * acos( cos( radians(?) ) *
            cos( radians( farms.lat ) )
            * cos( radians( farms.long ) - radians(?) )
            + sin( radians(?) ) *
            sin( radians( farms.lat ) ) ) )
            AS distance
        ";

        return $query-&amp;gt;select('farms.*')
            -&amp;gt;selectRaw($distanceQuery, [$lat, $long, $lat])
            -&amp;gt;orderBy('distance', 'asc');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Breaking Down the Scope&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL Query:&lt;/strong&gt; The Haversine formula is used within a raw SQL query to calculate the distance.&lt;br&gt;
&lt;strong&gt;6371&lt;/strong&gt; is the Earth's radius in kilometers. If you need the distance in miles, replace it with 3959.&lt;br&gt;
&lt;strong&gt;radians(?)&lt;/strong&gt; converts degrees to radians for the latitude and longitude.&lt;br&gt;
&lt;strong&gt;selectRaw&lt;/strong&gt;: This method allows us to include raw expressions in our query. The placeholders (?) are replaced with the provided latitude and longitude values.&lt;br&gt;
&lt;strong&gt;orderBy&lt;/strong&gt;: Finally, we sort the results by the calculated distance in ascending order, so the closest farms appear first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the Scope
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$lat = 37.7749;  // User's latitude or use $request-&amp;gt;lat
$long = -122.4194;  // User's longitude or use $request-&amp;gt;long

$nearestFarm = Farm::closest($lat, $long)-&amp;gt;first();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query will return a collection of Farm models ordered by their proximity to the user's location.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>maps</category>
      <category>coding</category>
    </item>
    <item>
      <title>Laravel routes: apiResource vs resource</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Mon, 18 Sep 2023 16:07:33 +0000</pubDate>
      <link>https://dev.to/johndivam/laravel-routes-apiresource-vs-resource-ij5</link>
      <guid>https://dev.to/johndivam/laravel-routes-apiresource-vs-resource-ij5</guid>
      <description>&lt;p&gt;Laravel routes application: using apiResource and resource. These methods help you create routes for a resource controller, following the RESTful conventions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;apiResource Function:&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;Route::apiResource('users', 'PostController');
GET           /users                      index   users.index
POST          /users                      store   users.store
GET           /users/{user}               show    users.show
PUT|PATCH     /users/{user}               update  users.update
DELETE        /users/{user}               destroy users.destroy

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;resource Function&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;Route::resource('users', 'PostController');
GET           /users                      index   users.index
GET           /users/create               create  users.create
POST          /users                      store   users.store
GET           /users/{user}               show    users.show
GET           /users/{user}/edit          edit    users.edit
PUT|PATCH     /users/{user}               update  users.update
DELETE        /users/{user}               destroy users.destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When using apiResource in Laravel, the routes are typically associated with the api middleware group by default. The api middleware group often excludes unnecessary middleware that is typically used for web requests, which can result in slightly &lt;strong&gt;faster performance&lt;/strong&gt; compared to using the web middleware group.&lt;/p&gt;

&lt;p&gt;The api middleware group usually includes middleware like throttle (for rate limiting) and auth:api (for API authentication). These are tailored for API routes, focusing on efficient handling of API requests.&lt;/p&gt;

&lt;p&gt;On the other hand, the web middleware group includes middleware that are more suited for traditional web application routes, which might not be necessary or optimal for API routes.&lt;/p&gt;

&lt;p&gt;So, if you're building an API and want to optimize for &lt;strong&gt;speed and efficiency&lt;/strong&gt;, using apiResource with the api middleware group is a good choice. It ensures that the routes are handled with middleware optimized for API requests&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>performance</category>
    </item>
    <item>
      <title>Laravel 4Ways to Select specific columns</title>
      <dc:creator>JohnDivam</dc:creator>
      <pubDate>Mon, 18 Sep 2023 15:57:57 +0000</pubDate>
      <link>https://dev.to/johndivam/laravel-4ways-to-select-specific-columns-3b5m</link>
      <guid>https://dev.to/johndivam/laravel-4ways-to-select-specific-columns-3b5m</guid>
      <description>&lt;p&gt;select specific columns from a database table using various methods provided by the Eloquent ORM (Object-Relational Mapping). Here are four common ways to select specific columns on a model:&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::select('id', 'name')-&amp;gt;get();
// or
$users = User::select(['id', 'name'])-&amp;gt;get();
// or
$users = User::find(3,['id', 'name']);
// or
$users = User::get(['id', 'name']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
