<?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: Techsolutionstuff</title>
    <description>The latest articles on DEV Community by Techsolutionstuff (@techsolutionstuff).</description>
    <link>https://dev.to/techsolutionstuff</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%2F653570%2F24831d91-9306-43bd-b04b-58b642057be5.png</url>
      <title>DEV Community: Techsolutionstuff</title>
      <link>https://dev.to/techsolutionstuff</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/techsolutionstuff"/>
    <language>en</language>
    <item>
      <title>Tips: Optimize Database Queries (2024) 🔥</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Wed, 01 May 2024 14:19:05 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/tips-optimize-database-queries-2024-1359</link>
      <guid>https://dev.to/techsolutionstuff/tips-optimize-database-queries-2024-1359</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F26r4nlxt1xe3r2jyahih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F26r4nlxt1xe3r2jyahih.png" alt="Tips: Optimize Database Queries (2024) " width="800" height="846"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>mysql</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel 11 Ajax Form Submit With Validation</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Wed, 01 May 2024 04:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/laravel-11-ajax-form-submit-with-validation-3pno</link>
      <guid>https://dev.to/techsolutionstuff/laravel-11-ajax-form-submit-with-validation-3pno</guid>
      <description>&lt;p&gt;Hello developers! In this guide, we'll see the laravel 11 Ajax form submitted with validation. &lt;/p&gt;

&lt;p&gt;Here, we'll learn about how to submit forms with Ajax and perform validation in Laravel 11. We'll submit a form without page refresh using jQuery Ajax.&lt;/p&gt;

&lt;p&gt;In this article, we'll create a form and it will open when click on the Create button then send an Ajax form request, and validate the form data into the controller.&lt;/p&gt;

&lt;p&gt;So, let's see AJAX form validation in laravel 11.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 1: Installing Laravel 11 Application

Step 2: Create Migration and Model

Step 3: Create a Controller

Step 4: Create a Routes

Step 5: Create Blade File

Step 6: Run the Laravel 11 App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 1: Installing Laravel 11 Application&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this step, we'll install the laravel 11 application using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project laravel/laravel laravel-11-ajax-form
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Create Migration and Model&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, we'll create a migration using the following command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Migration&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

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(): void()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table-&amp;gt;id();
            $table-&amp;gt;string('title');
            $table-&amp;gt;text('body');
            $table-&amp;gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(): void
    {
        Schema::dropIfExists('posts');
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we'll migrate the migration into the database using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we'll create a Post.php model using the following command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;app/Models/Post.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;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory;

    /**
     * Write code on Method
     *
     * @return response()
     */
    protected $fillable = [
        'title', 'body'
    ];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 3: Create a Controller&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, we'll create a new PostController.php using the following command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;app/Http/Controllers/PostController.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;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Models\Post;
use Illuminate\View\View;
use Illuminate\Http\JsonResponse;

class PostController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index(): View
    {
        $posts = Post::get();

        return view('posts', compact('posts'));
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    public function store(Request $request): JsonResponse
    {
        $request-&amp;gt;validate([
            'title' =&amp;gt; 'required',
            'body' =&amp;gt; 'required',
        ]);

        Post::create([
            'title' =&amp;gt; $request-&amp;gt;title,
            'body' =&amp;gt; $request-&amp;gt;body,
        ]);

        return response()-&amp;gt;json(['success' =&amp;gt; 'Post created successfully.']);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 4: Create Routes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, we'll define the routes in the web.php file.&lt;/p&gt;

&lt;p&gt;routes/web.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;?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PostController;

Route::get('posts', [ PostController::class, 'index' ]);
Route::post('posts', [ PostController::class, 'store' ])-&amp;gt;name('posts.store');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 5: Create Blade File&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we'll create a posts.blade.php file. In this file, we'll create a form and send an AJAX jQuery request.&lt;/p&gt;

&lt;p&gt;resources/views/posts.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;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Laravel 11 Ajax Form Submit With Validation - Techsolutionstuff&amp;lt;/title&amp;gt;
    &amp;lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"&amp;gt;
    &amp;lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" &amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" /&amp;gt;
    &amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" &amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;meta name="csrf-token" content="{{ csrf_token() }}" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="card mt-5"&amp;gt;
        &amp;lt;h3 class="card-header p-3"&amp;gt;&amp;lt;i class="fa fa-star"&amp;gt;&amp;lt;/i&amp;gt; Laravel 11 Ajax Form Submit With Validation - Techsolutionstuff&amp;lt;/h3&amp;gt;
        &amp;lt;div class="card-body"&amp;gt;

            &amp;lt;table class="table table-bordered mt-3"&amp;gt;
                &amp;lt;tr&amp;gt;
                    &amp;lt;th colspan="3"&amp;gt;
                        List Of Posts
                        &amp;lt;button type="button" class="btn btn-success float-end" data-bs-toggle="modal" data-bs-target="#postModal"&amp;gt;&amp;lt;i class="fa fa-plus"&amp;gt;&amp;lt;/i&amp;gt; 
                          Create Post
                        &amp;lt;/button&amp;gt;
                    &amp;lt;/th&amp;gt;
                &amp;lt;/tr&amp;gt;
                &amp;lt;tr&amp;gt;
                    &amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;
                    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;
                    &amp;lt;th&amp;gt;Body&amp;lt;/th&amp;gt;
                &amp;lt;/tr&amp;gt;
                @foreach($posts as $post)
                    &amp;lt;tr&amp;gt;
                        &amp;lt;td&amp;gt;{{ $post-&amp;gt;id }}&amp;lt;/td&amp;gt;
                        &amp;lt;td&amp;gt;{{ $post-&amp;gt;title }}&amp;lt;/td&amp;gt;
                        &amp;lt;td&amp;gt;{{ $post-&amp;gt;body }}&amp;lt;/td&amp;gt;
                    &amp;lt;/tr&amp;gt;
                @endforeach
            &amp;lt;/table&amp;gt;

        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;!-- Modal --&amp;gt;
&amp;lt;div class="modal fade" id="postModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"&amp;gt;
  &amp;lt;div class="modal-dialog"&amp;gt;
    &amp;lt;div class="modal-content"&amp;gt;
      &amp;lt;div class="modal-header"&amp;gt;
        &amp;lt;h5 class="modal-title" id="exampleModalLabel"&amp;gt;Create Post&amp;lt;/h5&amp;gt;
        &amp;lt;button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"&amp;gt;&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="modal-body"&amp;gt;
        &amp;lt;form id="ajax-form" action="{{ route('posts.store') }}"&amp;gt;
            @csrf

            &amp;lt;div class="alert alert-danger print-error-msg" style="display:none"&amp;gt;
                &amp;lt;ul&amp;gt;&amp;lt;/ul&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mb-3"&amp;gt;
                &amp;lt;label for="titleID" class="form-label"&amp;gt;Title:&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" id="titleID" name="title" class="form-control" placeholder="Name"&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mb-3"&amp;gt;
                &amp;lt;label for="bodyID" class="form-label"&amp;gt;Body:&amp;lt;/label&amp;gt;
                &amp;lt;textarea name="body" class="form-control" id="bodyID"&amp;gt;&amp;lt;/textarea&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="mb-3 text-center"&amp;gt;
                &amp;lt;button class="btn btn-success btn-submit"&amp;gt;&amp;lt;i class="fa fa-save"&amp;gt;&amp;lt;/i&amp;gt; Submit&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;

        &amp;lt;/form&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;

    $('#ajax-form').submit(function(e) {
        e.preventDefault();

        var url = $(this).attr("action");
        let formData = new FormData(this);

        $.ajax({
                type:'POST',
                url: url,
                data: formData,
                contentType: false,
                processData: false,
                success: (response) =&amp;gt; {
                    info('Form submitted successfully');                            
                    $('#postModal').hide();       
                },
                error: function(response){
                    $('#ajax-form').find(".print-error-msg").find("ul").html('');
                    $('#ajax-form').find(".print-error-msg").css('display','block');
                    $.each( response.responseJSON.errors, function( key, value ) {
                        $('#ajax-form').find(".print-error-msg").find("ul").append('&amp;lt;li&amp;gt;'+value+'&amp;lt;/li&amp;gt;');
                    });
                }
           });

    });

&amp;lt;/script&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 6: Run the Laravel 11 Application&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next, run the laravel 11 application using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;You might also like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/how-to-create-ajax-crud-operation-in-laravel-11"&gt;Read Also: How to Create AJAX CRUD Operation in Laravel 11&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/laravel-10-datatable-date-range-filter-using-ajax"&gt;Read Also: Laravel 10 Datatable Date Range Filter using AJAX&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laravel11</category>
      <category>ajax</category>
      <category>validation</category>
    </item>
    <item>
      <title>Laravel 11 Create, Run and Rollback Migration</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Mon, 29 Apr 2024 05:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/laravel-11-create-run-and-rollback-migration-10fg</link>
      <guid>https://dev.to/techsolutionstuff/laravel-11-create-run-and-rollback-migration-10fg</guid>
      <description>&lt;p&gt;In this guide, we'll see how to create, run, and roll back migration in laravel 11. &lt;/p&gt;

&lt;p&gt;Migrations are like version control for your database. Also, see run specific migration in laravel 11 and roll back specific migration in laravel 11.&lt;/p&gt;

&lt;p&gt;A migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create Migration&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, we'll create a migration using the following command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;After running the above command, you will see a new file in the database/migration folder.&lt;/p&gt;

&lt;p&gt;database/migrations/2024_04_06_144031_create_blogs_table.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;?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('blogs', function (Blueprint $table) {
            $table-&amp;gt;id();
            $table-&amp;gt;string('title');
            $table-&amp;gt;text('body');
            $table-&amp;gt;boolean('is_published')-&amp;gt;default(0);
            $table-&amp;gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('blogs');
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Run Migration&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, we'll migrate the migration into the database using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Run Specific Migration&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Run a specific migration using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan migrate --path=/database/migrations/2024_04_06_144031_create_blogs_table.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Migration Rollback&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Rollback a migration using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan migrate:rollback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Rollback Specific Migration&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Roll back a specific migration using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan migrate:rollback --path=database/migrations/2024_04_06_144031_create_blogs_table.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Reset Migration&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reset migration will roll back all the application's migrations.&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 migrate:reset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Column-modifiers&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In addition to the column types listed above, there are several column "modifiers" you may use when adding a column to a database table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::table('users', function (Blueprint $table) {
    $table-&amp;gt;string('email')-&amp;gt;nullable();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Dropping Columns&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To drop a column, you may use the dropColumn method on the schema builder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Schema::table('users', function (Blueprint $table) {
    $table-&amp;gt;dropColumn('votes');
});

Schema::table('users', function (Blueprint $table) {
    $table-&amp;gt;dropColumn(['votes', 'avatar', 'location']);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;You might also like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/how-to-add-foreign-key-in-laravel-10-migration"&gt;Read Also: How to Add Foreign Key in Laravel 10 Migration&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>migration</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel 10 Send Notifications in Slack Channel</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Fri, 26 Apr 2024 04:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/laravel-10-send-notifications-in-slack-channel-ffj</link>
      <guid>https://dev.to/techsolutionstuff/laravel-10-send-notifications-in-slack-channel-ffj</guid>
      <description>&lt;p&gt;Hey there! If you're a Laravel enthusiast like me, you probably understand the importance of effective team communication and collaboration. &lt;/p&gt;

&lt;p&gt;One powerful way to streamline communication within your team is by integrating Slack notifications into your Laravel applications.&lt;/p&gt;

&lt;p&gt;In this step-by-step guide, I'll walk you through sending notifications to a Slack channel using Laravel 10.&lt;/p&gt;

&lt;p&gt;So, let's see laravel 10 sends notifications in the Slack channel, how to send notifications to the Slack channel in laravel 8/9/10, real-time logging in laravel using Slack, and how to send logs in Slack Laravel 10.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Install Laravel 10&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you haven't already, start by installing Laravel 10 by using Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project laravel/laravel my-project "10.*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Configure Log File&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Laravel, there's a handy file called config/logging.php where you can tweak how your app logs information. This file gives you the power to set up different channels for logging in your application.&lt;/p&gt;

&lt;p&gt;config/logging.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;?php

use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

    'default' =&amp;gt; env('LOG_CHANNEL', 'stack'),

    'deprecations' =&amp;gt; [
        'channel' =&amp;gt; env('LOG_DEPRECATIONS_CHANNEL', 'null'),
        'trace' =&amp;gt; false,
    ],

    'channels' =&amp;gt; [
        'stack' =&amp;gt; [
            'driver' =&amp;gt; 'stack',
            'channels' =&amp;gt; ['single'],
            'ignore_exceptions' =&amp;gt; false,
        ],

        'single' =&amp;gt; [
            'driver' =&amp;gt; 'single',
            'path' =&amp;gt; storage_path('logs/laravel.log'),
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
        ],

        'daily' =&amp;gt; [
            'driver' =&amp;gt; 'daily',
            'path' =&amp;gt; storage_path('logs/laravel.log'),
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
            'days' =&amp;gt; 14,
        ],

        'slack' =&amp;gt; [
            'driver' =&amp;gt; 'slack',
            'url' =&amp;gt; env('LOG_SLACK_WEBHOOK_URL'),
            'username' =&amp;gt; 'Laravel Log',
            'emoji' =&amp;gt; ':boom:',
            'level' =&amp;gt; env('LOG_LEVEL', 'critical'),
        ],

        'papertrail' =&amp;gt; [
            'driver' =&amp;gt; 'monolog',
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
            'handler' =&amp;gt; env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
            'handler_with' =&amp;gt; [
                'host' =&amp;gt; env('PAPERTRAIL_URL'),
                'port' =&amp;gt; env('PAPERTRAIL_PORT'),
                'connectionString' =&amp;gt; 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
            ],
        ],

        'stderr' =&amp;gt; [
            'driver' =&amp;gt; 'monolog',
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
            'handler' =&amp;gt; StreamHandler::class,
            'formatter' =&amp;gt; env('LOG_STDERR_FORMATTER'),
            'with' =&amp;gt; [
                'stream' =&amp;gt; 'php://stderr',
            ],
        ],

        'syslog' =&amp;gt; [
            'driver' =&amp;gt; 'syslog',
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
        ],

        'errorlog' =&amp;gt; [
            'driver' =&amp;gt; 'errorlog',
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
        ],

        'null' =&amp;gt; [
            'driver' =&amp;gt; 'monolog',
            'handler' =&amp;gt; NullHandler::class,
        ],

        'emergency' =&amp;gt; [
            'path' =&amp;gt; storage_path('logs/laravel.log'),
        ],
    ],

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

&lt;/div&gt;



&lt;p&gt;In the log file, there are different options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'daily' =&amp;gt; [
            'driver' =&amp;gt; 'daily',
            'path' =&amp;gt; storage_path('logs/laravel.log'),
            'level' =&amp;gt; env('LOG_LEVEL', 'debug'),
            'days' =&amp;gt; 14,
        ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;driver: This tells laravel the driver to use.&lt;br&gt;
path: This tells Laravel where to write the logs to.&lt;br&gt;
level: This tells Laravel the type of log to be handled by this channel. It can be debug, critical, warning etc.&lt;br&gt;
days: The days option tells Laravel how long the log should be retained before deleting.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 3: Create a Slack App and Generate a Webhook URL&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To send notifications to your Slack channel, you'll need to create a Slack app and generate a webhook URL. Follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to your Slack workspace and navigate to the Apps section.&lt;/li&gt;
&lt;li&gt;Click on Create New App, and give your app a name.&lt;/li&gt;
&lt;li&gt;Navigate to the Incoming Webhooks section and toggle it on.&lt;/li&gt;
&lt;li&gt;Click on Add New Webhook to Workspace and select the channel where you want to send notifications.&lt;/li&gt;
&lt;li&gt;Copy the generated webhook URL.&lt;/li&gt;
&lt;li&gt;Slack will now generate a webhook URL for us. Copy it, head over to your .env file and add it to your app like below.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOG_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Open up the logging.php file then under channels array, since the default is set to stack, let's change the channels to slack from single and save the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'stack' =&amp;gt; [
            'driver' =&amp;gt; 'stack',
            'channels' =&amp;gt; ['slack'],
            'ignore_exceptions' =&amp;gt; false,
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 4: Test the Log Notification&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's test it out by opening up Tinker and running the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;info("This is just a tutorial demo logging");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You've successfully set up and sent notifications to a Slack channel using Laravel 10.&lt;/p&gt;




&lt;p&gt;You might also like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/how-to-create-rest-api-using-node-js-and-mongodb"&gt;Read Also: How to Create REST API using Node.js and MongoDB&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/toastr-notification-in-laravel-10-livewire-example"&gt;Read Also: Toastr Notification In Laravel 10 Livewire Example&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laravel10</category>
      <category>notification</category>
      <category>slack</category>
    </item>
    <item>
      <title>Multiple ways to Validate Email Addresses</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Wed, 24 Apr 2024 16:49:04 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/multiple-ways-to-validate-email-addresses-3k4n</link>
      <guid>https://dev.to/techsolutionstuff/multiple-ways-to-validate-email-addresses-3k4n</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujg36g4d9wqr6gni6th1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujg36g4d9wqr6gni6th1.png" alt="Multiple ways to Validate Email Addresses" width="800" height="886"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7hrbta35578dcvau2my.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7hrbta35578dcvau2my.png" alt="Multiple ways to Validate Email Addresses" width="800" height="1080"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxfmhkycqgxtpfc9qtu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxfmhkycqgxtpfc9qtu7.png" alt="Multiple ways to Validate Email Addresses" width="800" height="996"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>jquery</category>
      <category>webdev</category>
    </item>
    <item>
      <title>User Roles and Permissions Using Centralized Database in Laravel 10</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Wed, 24 Apr 2024 04:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/user-roles-and-permissions-using-centralized-database-in-laravel-10-47o1</link>
      <guid>https://dev.to/techsolutionstuff/user-roles-and-permissions-using-centralized-database-in-laravel-10-47o1</guid>
      <description>&lt;p&gt;Hey there! Welcome to my article on managing user roles and permissions using a centralized database in Laravel 10. If you're like me, you've probably worked on projects where managing user access levels can quickly become a headache.&lt;/p&gt;

&lt;p&gt;Whether granting specific permissions to certain users or defining different roles within your application, it can get complicated fast. Thankfully, Laravel provides us with powerful tools to streamline this process. With the advent of Laravel 10.&lt;/p&gt;

&lt;p&gt;In this article, I'll guide you through implementing user roles and permissions in Laravel 10 using a centralized database approach.&lt;/p&gt;

&lt;p&gt;So, let's see user roles and permissions using a centralized database in laravel 10, laravel 10 user roles and permissions, roles and permissions in laravel 8/9/10, and custom roles and permissions in laravel 10.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Setup Laravel 10 Project&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Begin by creating a new Laravel 10 project using Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project laravel/laravel user-role-permissions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Setup Database&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we'll setup the database configuration in the .env file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_CONNECTION_CENTRAL_DB=mysql
DB_HOST_CENTRAL_DB=127.0.0.1
DB_PORT_CENTRAL_DB=3306
DB_DATABASE_CENTRAL_DB=roles_and_permissions_laravel10
DB_USERNAME_CENTRAL_DB=root
DB_PASSWORD_CENTRAL_DB= 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run migrations to create these tables:&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 migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 3: Create Roles and Permissions Tables&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, create a roles and permissions table using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:migration create_roles_table
php artisan make:migration create_permissions_table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 4: Create Models&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After that, create a model for roles and permissions.&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:model Role
php artisan make:model Permission
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;App/Models/Role&lt;br&gt;
&lt;/p&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;
use Spatie\Permission\Models\Role as SpatieRole;

class Role extends SpatieRole
{
    protected $connection = 'mysql';
}   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;App/Models/Permission&lt;br&gt;
&lt;/p&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;
use Spatie\Permission\Models\Permission as SpatiePermission;

class Permission extends SpatiePermission
{
    protected $connection = 'mysql';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 5: Set Environment&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we'll add a set environment for mysql_central_db.&lt;/p&gt;

&lt;p&gt;config/database.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' =&amp;gt; env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' =&amp;gt; [

        'sqlite' =&amp;gt; [
            'driver' =&amp;gt; 'sqlite',
            'url' =&amp;gt; env('DATABASE_URL'),
            'database' =&amp;gt; env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' =&amp;gt; '',
            'foreign_key_constraints' =&amp;gt; env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' =&amp;gt; [
            'driver' =&amp;gt; 'mysql',
            'url' =&amp;gt; env('DATABASE_URL'),
            'host' =&amp;gt; env('DB_HOST', '127.0.0.1'),
            'port' =&amp;gt; env('DB_PORT', '3306'),
            'database' =&amp;gt; env('DB_DATABASE', 'forge'),
            'username' =&amp;gt; env('DB_USERNAME', 'forge'),
            'password' =&amp;gt; env('DB_PASSWORD', ''),
            'unix_socket' =&amp;gt; env('DB_SOCKET', ''),
            'charset' =&amp;gt; 'utf8mb4',
            'collation' =&amp;gt; 'utf8mb4_unicode_ci',
            'prefix' =&amp;gt; '',
            'prefix_indexes' =&amp;gt; true,
            'strict' =&amp;gt; true,
            'engine' =&amp;gt; null,
            'options' =&amp;gt; extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA =&amp;gt; env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'mysql_central_db' =&amp;gt; [
            'driver' =&amp;gt; 'mysql',
            'url' =&amp;gt; env('DATABASE_URL_CENTRAL_DB'),
            'host' =&amp;gt; env('DB_HOST_CENTRAL_DB', '127.0.0.1'),
            'port' =&amp;gt; env('DB_PORT_CENTRAL_DB', '3306'),
            'database' =&amp;gt; env('DB_DATABASE_CENTRAL_DB', 'forge'),
            'username' =&amp;gt; env('DB_USERNAME_CENTRAL_DB', 'forge'),
            'password' =&amp;gt; env('DB_PASSWORD_CENTRAL_DB', ''),
            'unix_socket' =&amp;gt; env('DB_SOCKET_CENTRAL_DB', ''),
            'charset' =&amp;gt; 'utf8mb4',
            'collation' =&amp;gt; 'utf8mb4_unicode_ci',
            'prefix' =&amp;gt; '',
            'prefix_indexes' =&amp;gt; true,
            'strict' =&amp;gt; false,
            'engine' =&amp;gt; null,
            'options' =&amp;gt; extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA =&amp;gt; env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'pgsql' =&amp;gt; [
            'driver' =&amp;gt; 'pgsql',
            'url' =&amp;gt; env('DATABASE_URL'),
            'host' =&amp;gt; env('DB_HOST', '127.0.0.1'),
            'port' =&amp;gt; env('DB_PORT', '5432'),
            'database' =&amp;gt; env('DB_DATABASE', 'forge'),
            'username' =&amp;gt; env('DB_USERNAME', 'forge'),
            'password' =&amp;gt; env('DB_PASSWORD', ''),
            'charset' =&amp;gt; 'utf8',
            'prefix' =&amp;gt; '',
            'prefix_indexes' =&amp;gt; true,
            'search_path' =&amp;gt; 'public',
            'sslmode' =&amp;gt; 'prefer',
        ],

        'sqlsrv' =&amp;gt; [
            'driver' =&amp;gt; 'sqlsrv',
            'url' =&amp;gt; env('DATABASE_URL'),
            'host' =&amp;gt; env('DB_HOST', 'localhost'),
            'port' =&amp;gt; env('DB_PORT', '1433'),
            'database' =&amp;gt; env('DB_DATABASE', 'forge'),
            'username' =&amp;gt; env('DB_USERNAME', 'forge'),
            'password' =&amp;gt; env('DB_PASSWORD', ''),
            'charset' =&amp;gt; 'utf8',
            'prefix' =&amp;gt; '',
            'prefix_indexes' =&amp;gt; true,
            // 'encrypt' =&amp;gt; env('DB_ENCRYPT', 'yes'),
            // 'trust_server_certificate' =&amp;gt; env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' =&amp;gt; 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer body of commands than a typical key-value system
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' =&amp;gt; [

        'client' =&amp;gt; env('REDIS_CLIENT', 'phpredis'),

        'options' =&amp;gt; [
            'cluster' =&amp;gt; env('REDIS_CLUSTER', 'redis'),
            'prefix' =&amp;gt; env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' =&amp;gt; [
            'url' =&amp;gt; env('REDIS_URL'),
            'host' =&amp;gt; env('REDIS_HOST', '127.0.0.1'),
            'username' =&amp;gt; env('REDIS_USERNAME'),
            'password' =&amp;gt; env('REDIS_PASSWORD'),
            'port' =&amp;gt; env('REDIS_PORT', '6379'),
            'database' =&amp;gt; env('REDIS_DB', '0'),
        ],

        'cache' =&amp;gt; [
            'url' =&amp;gt; env('REDIS_URL'),
            'host' =&amp;gt; env('REDIS_HOST', '127.0.0.1'),
            'username' =&amp;gt; env('REDIS_USERNAME'),
            'password' =&amp;gt; env('REDIS_PASSWORD'),
            'port' =&amp;gt; env('REDIS_PORT', '6379'),
            'database' =&amp;gt; env('REDIS_CACHE_DB', '1'),
        ],

    ],

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 6: Attach Roles and Permissions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this step, we'll attach roles and permissions in the config/permission.php file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'role' =&amp;gt; App\Models\Role::class,
'permission' =&amp;gt; App\Models\Permission::class,   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 7: Used Centralized Database&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this step, we'll use a centralized database with the help of env('DB_DATABASE_CENTRAL_DB').&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$customerRevenueCharges = DB::table('loads')
    -&amp;gt;select('users.company_name as customer_name',DB::raw("SUM(loads.commission_amount) as total_amount"))
    -&amp;gt;join(env('DB_DATABASE_CENTRAL_DB').'.users',env('DB_DATABASE_CENTRAL_DB').'.users.id','loads.user_id')
    -&amp;gt;orderBy('total_amount','DESC')
    -&amp;gt;groupBy('loads.user_id')
    -&amp;gt;take(10)
    -&amp;gt;cursor();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;You might also like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/how-to-add-dependent-validation-using-jquery-validate-js"&gt;Read Also: How to Add Dependent Validation using jQuery Validate.js&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/user-roles-and-permissions-without-package-laravel-9"&gt;Read Also: User Roles And Permissions Without Package Laravel 9&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laravel10</category>
      <category>mysql</category>
      <category>database</category>
    </item>
    <item>
      <title>How to Add Dependent Validation using jQuery Validate.js</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Mon, 22 Apr 2024 04:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/how-to-add-dependent-validation-using-jquery-validatejs-9c0</link>
      <guid>https://dev.to/techsolutionstuff/how-to-add-dependent-validation-using-jquery-validatejs-9c0</guid>
      <description>&lt;p&gt;Hey there! If you're like me, you know that making sure the information users input into your website is correct and secure is super important. &lt;/p&gt;

&lt;p&gt;That's where validation comes in handy, and today, I'm excited to walk you through adding a special kind of validation called dependent validation using jQuery Validate.js.&lt;/p&gt;

&lt;p&gt;Imagine you have a form where users must create a password and confirm it. It's crucial to ensure they've typed the same password twice, right?&lt;/p&gt;

&lt;p&gt;In this guide, I'll take you through the process step by step, making it easy to follow even if you're new to web development.&lt;/p&gt;

&lt;p&gt;So, let's see how to add dependent validation using jquery validate.js, jquery validation, depend validation using jquery, and condition-based validation using jquery validate.js.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Set Up Your HTML Form&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Begin by creating your HTML form with the necessary input fields. For this example, let's imagine a form with two fields: "Password" and "Confirm Password".&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;form id="myForm"&amp;gt;
  &amp;lt;label for="password"&amp;gt;Password:&amp;lt;/label&amp;gt;
  &amp;lt;input type="password" id="password" name="password"&amp;gt;

  &amp;lt;label for="confirm_password"&amp;gt;Confirm Password:&amp;lt;/label&amp;gt;
  &amp;lt;input type="password" id="confirm_password" name="confirm_password"&amp;gt;

  &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Include jQuery and jQuery Validate.js&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Make sure you have jQuery and jQuery Validate.js included in your project. You can do this by adding the following script tags in your HTML file.&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;script src="https://code.jquery.com/jquery-3.6.0.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/jquery.validation/1.19.3/jquery.validate.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 3: Write Your Validation Rules&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next, define your validation rules using jQuery Validate.js. In this case, we want to ensure that the "Confirm Password" field matches the value of the "Password" field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(document).ready(function() {
  $('#myForm').validate({
    rules: {
      password: {
        required: true,
        minlength: 8
      },
      confirm_password: {
        required: true,
        equalTo: '#password'
      }
    },
    messages: {
      password: {
        required: "Please enter a password",
        minlength: "Your password must be at least 8 characters long"
      },
      confirm_password: {
        required: "Please confirm your password",
        equalTo: "Passwords do not match"
      }
    }
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;rules: {
    'contact': {
      required: true,
      email: {
        depends: function(element) {
          return $("#email").is(":checked");
        }
      },
      number: {
        depends: function(element) {
          return $("#phone_number").is(":checked");
        }
      }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;&amp;lt;form id="myForm"&amp;gt;
  &amp;lt;label for="age"&amp;gt;Age:&amp;lt;/label&amp;gt;
  &amp;lt;input type="number" id="age" name="age"&amp;gt;

  &amp;lt;label for="grade"&amp;gt;Grade:&amp;lt;/label&amp;gt;
  &amp;lt;select id="grade" name="grade"&amp;gt;
    &amp;lt;option value="1"&amp;gt;1st Grade&amp;lt;/option&amp;gt;
    &amp;lt;option value="2"&amp;gt;2nd Grade&amp;lt;/option&amp;gt;
    &amp;lt;option value="3"&amp;gt;3rd Grade&amp;lt;/option&amp;gt;
    &amp;lt;!-- More options up to 12th grade --&amp;gt;
  &amp;lt;/select&amp;gt;

  &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
$(document).ready(function() {
  $('#myForm').validate({
    rules: {
      age: {
        required: true,
        min: 1
      },
      grade: {
        required: true,
        depends: function(element) {
          // Check if age is under 18
          return $('#age').val() &amp;lt; 18;
        },
        max: 10
      }
    },
    messages: {
      age: {
        required: "Please enter your age",
        min: "Age must be a positive number"
      },
      grade: {
        required: "Please select your grade",
        max: "You cannot select a grade higher than 10th grade if you're under 18"
      }
    }
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "Grade" field's validation is dependent on the value entered in the "Age" field. If the user's age is under 18, they won't be able to select a grade higher than 10th grade.&lt;/p&gt;




&lt;p&gt;You might also like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/role-and-permission-in-laravel-9-tutorial"&gt;Read Also: Role And Permission In Laravel 9 Tutorial&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/how-to-create-crud-operation-in-laravel-11"&gt;Read Also: How to Create CRUD Operation in Laravel 11&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laravel11</category>
      <category>jquery</category>
      <category>validation</category>
    </item>
    <item>
      <title>How to Create Services in Laravel 10</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Fri, 19 Apr 2024 05:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/how-to-create-services-in-laravel-10-1jg0</link>
      <guid>https://dev.to/techsolutionstuff/how-to-create-services-in-laravel-10-1jg0</guid>
      <description>&lt;p&gt;Hey there, Ever found yourself writing the same chunk of code over and over again in your Laravel controllers? Well, I've got just the solution for you! In this guide, I'm going to show you how to create services in Laravel 10.&lt;/p&gt;

&lt;p&gt;Services are like little helpers that contain reusable blocks of code. &lt;/p&gt;

&lt;p&gt;They're fantastic for keeping your controllers clean and focused, and they make your code easier to maintain and understand.&lt;/p&gt;

&lt;p&gt;By the end of this guide, you'll be able to create your own services in Laravel and use them to streamline your application's logic.&lt;/p&gt;

&lt;p&gt;So, let's see how to create services in laravel 10, laravel services, what is service in laravel 10, create and register the service, and how to create a service class in laravel 8/9/10.&lt;/p&gt;

&lt;p&gt;What is the difference between helper and service in laravel?&lt;/p&gt;

&lt;p&gt;In Laravel, both helpers and services play crucial roles in organizing and facilitating code, but they serve different purposes and are used in different contexts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Helpers:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Helpers are utility functions or classes that provide commonly used functionalities throughout your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are typically globally accessible and are used to perform common tasks like string manipulation, array operations, generating URLs, formatting data, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Laravel provides a set of built-in helper functions and classes that you can use directly in your code without needing to import or instantiate them explicitly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Services:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Services, on the other hand, are classes that encapsulate specific business logic or functionality within your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are designed to handle more complex and domain-specific tasks, such as interacting with databases, making API calls, performing calculations, and implementing business rules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Services are typically instantiated and used within your application's components (such as controllers, commands, or other services) to perform specific operations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unlike helpers, services are not globally accessible by default. Instead, they are typically instantiated and injected into the components that require them, following the principles of dependency injection.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Create a New Service Class&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To create a new service class, simply generate a new PHP file in your app/Services directory. You can name this file based on the functionality it provides. For example, MyService.php.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 2: Write Your Service Logic&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next, let's define the logic for your service. This could include interacting with models, making API calls, performing calculations, or any other business logic specific to your application.&lt;/p&gt;

&lt;p&gt;app/Services/MyService.php&lt;br&gt;
&lt;/p&gt;

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

class MyService
{
    public function doSomething()
    {
        // Your business logic goes here
        return "I'm doing something!";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 3: Utilize Your Service in Controllers&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that your service is ready, let's use it in your controllers. Simply inject your service class into the constructor or method where you need it, and then call its methods as needed.&lt;/p&gt;

&lt;p&gt;app/Http/Controllers/MyController.php&lt;br&gt;
&lt;/p&gt;

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

use App\Services\MyService;

class MyController extends Controller
{
    protected $myService;

    public function __construct(MyService $myService)
    {
        $this-&amp;gt;myService = $myService;
    }

    public function someMethod()
    {
        $result = $this-&amp;gt;myService-&amp;gt;doSomething();
        return response()-&amp;gt;json(['message' =&amp;gt; $result]);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, MyService contains a method doSomething() that returns a simple message. &lt;/p&gt;

&lt;p&gt;The MyController injects an instance of MyService through its constructor and calls the doSomething() method. Finally, it returns a JSON response with the result.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 4: Register Your Service (Optional)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you're using Laravel's service container to inject dependencies automatically, you don't need to register your service explicitly.&lt;/p&gt;

&lt;p&gt;However, if you prefer manual dependency injection or need to customize how your service is instantiated, you can register it in the AppServiceProvider.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Conclusion&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that's it! You've successfully created a service in Laravel 10 and integrated it into your application.&lt;/p&gt;




&lt;p&gt;You might also like:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/how-to-create-services-in-laravel-10"&gt;Read Also: How to Process Large CSV Files with Laravel 10&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/role-and-permission-in-laravel-9-tutorial"&gt;Read Also: Role And Permission In Laravel 9 Tutorial&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>laravel10</category>
      <category>services</category>
    </item>
    <item>
      <title>How to Process Large CSV Files with Laravel 10</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Wed, 17 Apr 2024 05:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/how-to-process-large-csv-files-with-laravel-10-1d9p</link>
      <guid>https://dev.to/techsolutionstuff/how-to-process-large-csv-files-with-laravel-10-1d9p</guid>
      <description>&lt;p&gt;Hey folks! Are you tired of feeling overwhelmed by those massive CSV files in your Laravel projects? Well, I've got some good news for you! &lt;/p&gt;

&lt;p&gt;In this guide, I'm going to walk you through the process of handling those hefty CSV files with ease using Laravel.&lt;/p&gt;

&lt;p&gt;By the end of this guide, you'll have the skills and confidence to tackle those giant CSV files like a pro, thanks to the power of Laravel and some nifty tools.&lt;/p&gt;

&lt;p&gt;In this article, we'll see how to process large CSV files with laravel 10, laravel 10 imports large CSV files, how to handle large CSV files in laravel 8/9/10, and how to import CSV files using spatie/simple-excel.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Set Up Your Laravel Project&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First things first, let's get our Laravel project up and running. If you haven't already, install Laravel by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;laravel new my-laravel-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Install the spatie/simple-excel Package&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next, let's install the spatie/simple-excel package via Composer. In your terminal, navigate to your project directory and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require spatie/simple-excel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we'll use SimpleExcelReader to load it up. by default, it returns you a LazyCollection – think of it as a more considerate way to handle your data without exhausting your server's memory. This means you can process the file bit by bit.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 3: Create a Laravel Job for importing CSV&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we'll create a job using the following command.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;App/Jobs/ImportCSV.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;?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\SimpleExcel\SimpleExcelReader;

class ImportCSV implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        SimpleExcelReader::create(storage_path('app/public/products.csv'))
            -&amp;gt;useDelimiter(',')
            -&amp;gt;useHeaders(['ID', 'title', 'description'])
            -&amp;gt;getRows()
            -&amp;gt;chunk(5000)
            -&amp;gt;each(
                // Here we have a chunk of 5000 products
            );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's is follow some steps to import large CSV files.&lt;/p&gt;

&lt;p&gt;Chunking the CSV: We'll split the big file into smaller parts, making it easier to handle. This gives us smaller chunks to work with, which is much simpler.&lt;/p&gt;

&lt;p&gt;Job Dispatching: We'll send each of these smaller chunks as separate tasks. This helps us manage the workload better and is gentler on your server.&lt;/p&gt;

&lt;p&gt;Database Insertion: Then, we'll smoothly add each chunk to the database. It's a straightforward process that ensures everything goes in neatly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Chunking the CSV&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With our LazyCollection set up, we'll break down the CSV into smaller parts. It's similar to slicing a huge sandwich into smaller, manageable pieces.&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 ImportProductChunk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For each part of the CSV file, we'll create and start a job. These jobs act like dedicated workers, each handling a portion of the data and inserting it into your database with care.&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\Jobs;

use App\Models\Product;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;

class ImportProductChunk implements ShouldBeUnique, ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $uniqueFor = 3600;

    /**
     * Create a new job instance.
     */
    public function __construct(
        public $chunk
    ) {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        $this-&amp;gt;chunk-&amp;gt;each(function (array $row) {
            Model::withoutTimestamps(fn () =&amp;gt; Product::updateOrCreate([
                'product_id' =&amp;gt; $row['ID'],
                'title' =&amp;gt; $row['title'],
                'description' =&amp;gt; $row['description'],
           ]));
        });
    }

    public function uniqueId(): string
    {
        return Str::uuid()-&amp;gt;toString();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Ensuring Uniqueness&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One important thing to remember is to use $uniqueFor and uniqueId in your jobs. It's similar to giving each worker a special ID badge. This way, you ensure that no two workers end up doing the same job, which is really bad for efficiency.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Dispatching Jobs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In our ImportCSV job, we'll send out a job for every chunk using each method.&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\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\SimpleExcel\SimpleExcelReader;

class ImportCSV implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        SimpleExcelReader::create(storage_path('app/public/products.csv'))
            -&amp;gt;useDelimiter(',')
            -&amp;gt;useHeaders(['ID', 'title', 'description'])
            -&amp;gt;getRows()
            -&amp;gt;chunk(5000)
            -&amp;gt;each(
                fn ($chunk) =&amp;gt; ImportProductChunk::dispatch($chunk)
            );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! Your large CSV files are ready to be processed efficiently, with each part handled separately, avoiding any memory issues. If you're pressed for time, simply add more workers to speed up the process.&lt;/p&gt;




&lt;p&gt;You might also like:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/how-to-process-large-csv-files-with-laravel-10"&gt;Read Also: How to Import CSV File in Laravel 10 using League/csv&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/efficient-csv-file-uploads-in-laravel-10-with-python"&gt;Read Also: Efficient CSV File Uploads in Laravel 10 with Python&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/how-to-import-csv-file-in-mysql-using-php"&gt;Read Also: How To Import CSV File In MySQL Using PHP&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>csv</category>
      <category>excel</category>
    </item>
    <item>
      <title>How to Add Flatpickr Time Picker Example</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Mon, 15 Apr 2024 05:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/how-to-add-flatpickr-time-picker-example-4hb4</link>
      <guid>https://dev.to/techsolutionstuff/how-to-add-flatpickr-time-picker-example-4hb4</guid>
      <description>&lt;p&gt;Hello, developers! Today, let's explore the world of time selection and learn how to integrate a sleek Time Picker into our web applications using Flatpickr. &lt;/p&gt;

&lt;p&gt;Flatpickr, known for its simplicity and flexibility, is an excellent choice for adding date and time-picking functionalities.&lt;/p&gt;

&lt;p&gt;In this guide, I'll walk you through the process step by step, keeping it straightforward with CDN (Content Delivery Network) files.&lt;/p&gt;

&lt;p&gt;In this article, I'll give you examples of timer pickers, time picker with AM/PM, 24-hour time picker, and preloading time. Also, you can use it in laravel 8, laravel 9, laravel 10 and PHP.&lt;/p&gt;

&lt;p&gt;So, let's see how to add a flatpickr time picker example, time picker, flatpickr time format, flatpickr 24 hour time, time picker cdn, time picker with am pm, jquery time picker with am pm.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Setting Up Flatpickr&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First things first, make sure Flatpickr is included in your project. You can either download it or use the CDN. For simplicity, let's go with the CDN:&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;!-- Include Flatpickr CSS and JS via CDN --&amp;gt;
&amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css"&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/flatpickr"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Create an HTML Input Element&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add an input field to your HTML file with a class that you'll use for initializing Flatpickr:&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;input type="text" class="time-picker" placeholder="Select Time"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Create an HTML file (e.g., index.html) and include the necessary CDN links for Flatpickr:&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Flatpickr Time Picker Example - Techsolutionstuff&amp;lt;/title&amp;gt;

    &amp;lt;!-- Flatpickr CSS CDN --&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr@4.6.9/dist/flatpickr.min.css"&amp;gt;

    &amp;lt;!-- Flatpickr JS CDN --&amp;gt;
    &amp;lt;script src="https://cdn.jsdelivr.net/npm/flatpickr@4.6.9/dist/flatpickr.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;input type="text" class="time-picker" placeholder="Select Time"&amp;gt;

    &amp;lt;script&amp;gt;
        // Initialize Flatpickr with Time Picker
        flatpickr('.time-picker', {
            enableTime: true,
            noCalendar: true,
            dateFormat: 'H:i',
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;24-hour Time Picker&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
        // Initialize Flatpickr with Time Picker
        flatpickr('.time-picker', {
                enableTime: true,
                noCalendar: true,
                dateFormat: "H:i",
                time_24hr: true
        });
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Time Picker w/ Limits&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
        // Initialize Flatpickr with Time Picker
        flatpickr('.time-picker', {
                enableTime: true,
                noCalendar: true,
                dateFormat: "H:i",
                minTime: "14:00",
                maxTime: "20:30",
        });
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Preloading Time&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
        // Initialize Flatpickr with Time Picker
        flatpickr('.time-picker', {
                enableTime: true,
                noCalendar: true,
                dateFormat: "H:i",
                defaultDate: "15:30"
        });
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;You might also like:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/bootstrap-datetimepicker-example"&gt;Read Also: Bootstrap DateTimepicker Example&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://techsolutionstuff.com/post/bootstrap-datetimepicker-example"&gt;Read Also: Date Range Calendar in Flatpickr Example&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>javascript</category>
      <category>flatpickr</category>
    </item>
    <item>
      <title>Date Range Calendar in Flatpickr Example</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Fri, 12 Apr 2024 05:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/date-range-calendar-in-flatpickr-example-f6c</link>
      <guid>https://dev.to/techsolutionstuff/date-range-calendar-in-flatpickr-example-f6c</guid>
      <description>&lt;p&gt;Hello, developers! Today, let's explore how to implement a Date Range Calendar in your web applications using Flatpickr. &lt;/p&gt;

&lt;p&gt;Flatpickr is a lightweight and customizable JavaScript date picker library, and the best part? We're going to keep things simple by using CDN (Content Delivery Network) files.&lt;/p&gt;

&lt;p&gt;In this article, I'll give a step-by-step guide for the date range calendar in flatpickr in laravel 8, laravel 9, laravel 10, and PHP.&lt;/p&gt;

&lt;p&gt;So, let's see the date range calendar in flatpickr example, flatpickr date range, how to set date range in datepicker, how to set date range in flatpickr, date range picker laravel 8/9/10.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Setting Up Flatpickr&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First things first, make sure Flatpickr is included in your project. You can either download it or use the CDN. For simplicity, let's go with the CDN:&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;!-- Include Flatpickr CSS and JS via CDN --&amp;gt;
&amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css"&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/flatpickr"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Create an HTML Input Element&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add an input field to your HTML file with a class that you'll use for initializing Flatpickr:&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;input type="text" class="date-range-picker" placeholder="Select Date Range"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Create an HTML file (e.g., index.html) and include the necessary CDN links for Flatpickr:&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Date Range Calendar with Flatpickr&amp;lt;/title&amp;gt;

    &amp;lt;!-- Flatpickr CSS CDN --&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr@4.6.9/dist/flatpickr.min.css"&amp;gt;

    &amp;lt;!-- Flatpickr JS CDN --&amp;gt;
    &amp;lt;script src="https://cdn.jsdelivr.net/npm/flatpickr@4.6.9/dist/flatpickr.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;input type="text" class="date-range-picker" placeholder="Select Date Range"&amp;gt;

    &amp;lt;script&amp;gt;
        // Initialize Flatpickr
        flatpickr('.date-range-picker', {
            mode: 'range',
            dateFormat: 'Y-m-d',
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that disabled dates (by either minDate, maxDate, enable or disable) will not be allowed in selections.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    mode: "range",
    minDate: "today",
    dateFormat: "Y-m-d",
    disable: [
        function(date) {
            // disable every multiple of 8
            return !(date.getDate() % 8);
        }
    ]
}

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

&lt;/div&gt;



&lt;p&gt;Preloading range dates&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    mode: "range",
    dateFormat: "Y-m-d",
    defaultDate: ["2024-02-10", "2016-02-20"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! In just a few simple steps, we've integrated a Date Range Calendar into our web application using Flatpickr with CDN files.&lt;/p&gt;




&lt;p&gt;You might also like:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/bootstrap-date-range-picker-example"&gt;Read Also: Bootstrap Date Range Picker Example&lt;/a&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/laravel-10-datatable-date-range-filter-using-ajax"&gt;Read Also: Laravel 10 Datatable Date Range Filter using AJAX&lt;/a&gt;&lt;/strong&gt;
&lt;/h4&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>flatpickr</category>
      <category>calendar</category>
    </item>
    <item>
      <title>How to Disable Dates in Flatpickr Example</title>
      <dc:creator>Techsolutionstuff</dc:creator>
      <pubDate>Wed, 10 Apr 2024 05:30:00 +0000</pubDate>
      <link>https://dev.to/techsolutionstuff/how-to-disable-dates-in-flatpickr-example-2mnn</link>
      <guid>https://dev.to/techsolutionstuff/how-to-disable-dates-in-flatpickr-example-2mnn</guid>
      <description>&lt;p&gt;Greetings developers! 🌟 Today, we embark on a journey to master the art of disabling dates in Flatpickr, the date picker library that brings both elegance and functionality to your projects.&lt;/p&gt;

&lt;p&gt;Whether you need to restrict specific dates, block out ranges, or dynamically disable dates using a function, Flatpickr has the flexibility you crave.&lt;/p&gt;

&lt;p&gt;Let's dive in and harness the full potential of date control with Flatpickr! 📅✨&lt;/p&gt;

&lt;p&gt;So, let's see how to disable dates in flatpickr example, disable date in date picker, specific date disable in flatpickr, past date disable in flatpickr, and date range disable in flatpickr.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Step 1: Setting Up Flatpickr&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First things first, make sure Flatpickr is included in your project. You can either download it or use the CDN. For simplicity, let's go with the CDN:&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;!-- Include Flatpickr CSS and JS via CDN --&amp;gt;
&amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css"&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/flatpickr"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 2: Create an HTML Input Element&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create an HTML input element to serve as your date picker. Give it a unique ID, such as "myDatePicker."&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;!-- Your HTML input element --&amp;gt;
&amp;lt;input type="text" id="myDatePicker" placeholder="Select a date"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 3: Disable Specific Dates&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's start by disabling specific dates. In this example, we'll block out January 15, 2024.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize Flatpickr and disable specific date
const myDatePicker = flatpickr("#myDatePicker", {
    disable: ["2024-01-15"],
});
// Initialize Flatpickr and disable specific date
const myDatePicker = flatpickr("#myDatePicker", {
    disable: ["2025-01-30", "2025-02-21", "2025-03-08", new Date(2025, 4, 9) ],
    dateFormat: "Y-m-d",
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 4: Disable a Date Range&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, let's disable a date range, say from January 1, 2024, to January 10, 2024.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize Flatpickr and disable date range
const myDatePicker = flatpickr("#myDatePicker", {
    disable: [
        { from: "2024-01-01", to: "2024-01-10" }
    ],
});
// Initialize Flatpickr and disable date range
const myDatePicker = flatpickr("#myDatePicker", {
    dateFormat: "Y-m-d",
    disable: [
        {
            from: "2025-04-01",
            to: "2025-05-01"
        },
        {
            from: "2025-09-01",
            to: "2025-12-01"
        }
    ],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Step 5: Disable Dates Using a Function&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more dynamic control, let's use a function to disable weekends. This example demonstrates how to disable Saturdays and Sundays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize Flatpickr and disable dates using a function
const myDatePicker = flatpickr("#myDatePicker", {
    disable: [
        function(date) {
            // Disable weekends (Saturdays and Sundays)
            return (date.getDay() === 0 || date.getDay() === 6);
        }
    ],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! You've successfully wielded the power of Flatpickr to disable specific dates, date ranges, and even utilized a function for dynamic date control.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;a href="https://techsolutionstuff.com/post/how-to-set-mindate-and-maxdate-in-flatpickr"&gt;Read Also: How to set minDate and maxDate in Flatpickr&lt;/a&gt;&lt;/strong&gt;
&lt;/h4&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>flatpickr</category>
      <category>dates</category>
    </item>
  </channel>
</rss>
