<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Balwant Singh on Medium]]></title>
        <description><![CDATA[Stories by Balwant Singh on Medium]]></description>
        <link>https://medium.com/@balwantsingh37807?source=rss-9b66d1ff0bd4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ypChPUNs-3IZt_7fp5NXCw.jpeg</url>
            <title>Stories by Balwant Singh on Medium</title>
            <link>https://medium.com/@balwantsingh37807?source=rss-9b66d1ff0bd4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:57:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@balwantsingh37807/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating Apache Kafka in Laravel: Real-time Database Synchronization with Debezium Connector]]></title>
            <link>https://medium.com/simform-engineering/integrating-apache-kafka-in-laravel-real-time-database-synchronization-with-debezium-connector-2506bc8f37a7?source=rss-9b66d1ff0bd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2506bc8f37a7</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[debezium]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[kafka-streams]]></category>
            <dc:creator><![CDATA[Balwant Singh]]></dc:creator>
            <pubDate>Wed, 05 Jul 2023 07:40:58 GMT</pubDate>
            <atom:updated>2023-07-05T07:40:58.095Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Empower your Laravel application with the latest and most accurate data by leveraging real-time database synchronization.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1u3zBZmdWlvU9pFoIYXAg.png" /></figure><p>In today’s fast-paced digital world, real-time data synchronization is crucial for many web applications. In this tutorial, we will explore how to integrate Apache Kafka and the Debezium connector into a Laravel application to achieve efficient and reliable real-time data synchronization between two databases.</p><h4>Prerequisites:</h4><blockquote>Laravel is installed on your local machine.</blockquote><blockquote>rdkafka php extension</blockquote><blockquote>Docker is installed to create a local development environment.</blockquote><blockquote>Basic knowledge of Laravel, Docker, and Apache Kafka concepts.</blockquote><h4>Setting up the development environment</h4><p>We will begin by creating a local development environment using Docker. A Docker Compose file will be provided, which includes the necessary services such as ZooKeeper, Kafka, Schema Registry, MySQL, Connect Debezium, and Kafka Manager. With a few configurations and Docker container orchestration, our development environment will be ready for integration.</p><pre>version: &#39;3&#39;<br>services:<br>    zookeeper:<br>        image: confluentinc/cp-zookeeper:6.2.0<br>        container_name: zookeeper<br>        environment:<br>            ZOOKEEPER_CLIENT_PORT: 2181<br>            ZOOKEEPER_TICK_TIME: 2000<br><br>    kafka:<br>        image: confluentinc/cp-kafka:6.2.0<br>        hostname: kafka<br>        container_name: kafka<br>        depends_on:<br>            - zookeeper<br>        ports:<br>            - &quot;29092:29092&quot;<br>        environment:<br>            KAFKA_BROKER_ID: 1<br>            KAFKA_ZOOKEEPER_CONNECT: &#39;zookeeper:2181&#39;<br>            KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT<br>            KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092<br>            KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1<br>            KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1<br>            KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1<br>            KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0<br>            CONFLUENT_METRICS_ENABLE: &#39;false&#39;<br>            KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1<br><br>    schema-registry:<br>        image: confluentinc/cp-schema-registry:6.2.0<br>        hostname: schema-registry<br>        container_name: schema-registry<br>        depends_on:<br>            - zookeeper<br>            - kafka<br>        ports:<br>            - &quot;8081:8081&quot;<br>        environment:<br>            SCHEMA_REGISTRY_HOST_NAME: schema-registry<br>            SCHEMA_REGISTRY_LISTENERS: &#39;http://0.0.0.0:8081&#39;<br>            SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: &#39;PLAINTEXT://kafka:9092&#39;<br><br>    mysql:<br>        image: debezium/example-mysql:1.2<br>        container_name: mysql<br>        ports:<br>            - 3307:3306<br>        environment:<br>            - MYSQL_ROOT_PASSWORD=debezium<br>            - MYSQL_USER=mysqluser<br>            - MYSQL_PASSWORD=mysqlpw<br>        volumes:<br>            - ${PWD}/data/movies.sql:/docker-entrypoint-initdb.d/z99_dump.sql<br><br>    connect-debezium:<br>        image: debezium/connect:1.6<br>        container_name: connect-debezium<br>        depends_on:<br>            - kafka<br>            - mysql<br>            - schema-registry<br>        ports:<br>            - 8083:8083<br>        environment:<br>            BOOTSTRAP_SERVERS: kafka:9092<br>            GROUP_ID: connect-debezium<br>            CONFIG_STORAGE_TOPIC: docker-connect-debezium-configs<br>            OFFSET_STORAGE_TOPIC: docker-connect-debezium-offsets<br>            STATUS_STORAGE_TOPIC: docker-connect-debezium-status<br>            KEY_CONVERTER: io.confluent.connect.avro.AvroConverter<br>            VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter<br>            CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081<br>            CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081<br>        volumes:<br>            - ${PWD}/scripts:/scripts<br><br>    kafka-manager:<br>        image: hlebalbau/kafka-manager:latest<br>        container_name: kafka-manager<br>        depends_on:<br>            - kafka<br>        ports:<br>            - &quot;9000:9000&quot;<br>        environment:<br>            - ZK_HOSTS=zookeeper:2181<br>            - APPLICATION_SECRET=letmein</pre><p>Also, the necessary scripts and SQL files are mentioned in this tutorial. <strong>You can access it from the GitHub repository I provided at the end of this blog</strong>. Inside the repository, you will find the scripts needed to run the Docker Compose setup, as well as the SQL file used for initializing the MySQL database. Feel free to explore the repository, clone it to your local environment, and adapt the code and configurations to suit your specific needs.</p><h4>Installing Kafka dependencies in Laravel</h4><p>Next, we will install the Kafka library in our Laravel application using Composer. This library provides the necessary tools and classes to interact with the Kafka broker. We will also configure Laravel to establish a connection with the Kafka broker, specifying the required configuration details.</p><pre>composer require mateusjunges/laravel-kafka</pre><pre>php artisan vendor:publish --tag=laravel-kafka-config</pre><h4>Configuring the Debezium connector</h4><p>The Debezium connector is a powerful tool that captures database changes and streams them to Kafka topics. We will configure the Debezium connector to connect to our MySQL databases, specify the tables we want to capture changes from, and map them to Kafka topics. This step will ensure that the connector captures the desired data for synchronization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*zQ5UpHKMsF4sMnBx9FS50A.png" /><figcaption>Credit: <a href="https://cdn.confluent.io/wp-content/uploads/kafka_connect-1.png">Source</a></figcaption></figure><p>At this point, we will consume the Kafka topics in our Laravel application using the Kafka consumer library. We will set up a consumer that retrieves the data stream from Kafka and processes it in real-time. With each event received from the Debezium connector, we will apply the necessary modifications to keep our synchronized database up to date.</p><p>First, we need to create a Laravel command for consuming Kafka events. Run the following command:</p><pre>php artisan make:command KafkaConsumer</pre><p>Next, register the command into the kernel.php file:</p><pre>protected $commands = [<br>        Commands\KafkaConsumer::class,<br>    ];</pre><p>Now, let’s see what the KafkaConsumer command should look like:</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use App\Events\MovieDataReceived;<br>use Illuminate\Console\Command;<br>use Junges\Kafka\Contracts\KafkaConsumerMessage;<br>use Junges\Kafka\Facades\Kafka;<br><br>class KafkaConsumer extends Command<br>{<br>    protected $signature = &#39;kafka:consume&#39;;<br>    protected $description = &#39;Consume messages from Kafka topics&#39;;<br><br>    public function handle()<br>    {<br>        $consumer = Kafka::createConsumer([&#39;movies&#39;])<br>            -&gt;withHandler(function (KafkaConsumerMessage $message) {<br>                event(new MovieDataReceived(json_encode($message-&gt;getBody())));<br>                $this-&gt;info(&#39;Received message: &#39; . json_encode($message-&gt;getBody()));<br>            })-&gt;build();<br><br>        $consumer-&gt;consume();<br>    }<br>}</pre><p>For Kafka events, we dispatch a Laravel event that handles data modification between two databases. Create the MovieDataReceived event using the following command:</p><pre>php artisan make:event MovieDataRecived</pre><pre>&lt;?php<br><br>namespace App\Events;<br><br>use Illuminate\Foundation\Events\Dispatchable;<br>use Illuminate\Queue\SerializesModels;<br><br>class MovieDataReceived<br>{<br>    use Dispatchable, SerializesModels;<br><br>    public $data;<br><br>    /**<br>     * Create a new event instance.<br>     *<br>     * @return void<br>     */<br>    public function __construct($data)<br>    {<br>        $this-&gt;data = $data;<br>    }<br>}</pre><p>Next, create a listener for the event to handle data modification and insertion into our local database using the following command:</p><pre>php artisan make:listener SyncMovieData --event=MovieDataReceived</pre><p>Register the event listener in the EventServiceProvider:</p><pre>protected $listen = [<br>        MovieDataReceived::class =&gt; [<br>            SyncMovieData::class,<br>        ],<br>    ];</pre><p>Here’s the modified SyncMovieData listener class:</p><pre>&lt;?php<br><br>namespace App\Listeners;<br><br>use App\Events\MovieDataReceived;<br>use App\Models\Movie;<br>use Illuminate\Contracts\Queue\ShouldQueue;<br>use Illuminate\Queue\InteractsWithQueue;<br>use Illuminate\Support\Facades\Log;<br><br>class SyncMovieData implements ShouldQueue<br>{<br>    /**<br>     * Handle the event.<br>     */<br>    public function handle(MovieDataReceived $event): void<br>    {<br>        // Extract the movie data from the event<br>        $data = json_decode($event-&gt;data);<br><br>        Movie::updateOrCreate([&#39;movie_id&#39; =&gt; $data-&gt;movie_id], [<br>            &#39;movie_id&#39; =&gt; $data-&gt;movie_id,<br>            &#39;title&#39; =&gt; $data-&gt;title,<br>            &#39;release_year&#39; =&gt; $data-&gt;release_year,<br>            &#39;country&#39; =&gt; $data-&gt;country,<br>            &#39;actors&#39; =&gt; $data-&gt;actors,<br>            &#39;genres&#39; =&gt; $data-&gt;genres<br>        ]);<br><br>        Log::info(&#39;Movie data synchronized: &#39; . $data-&gt;movie_id);<br>    }<br>}</pre><p>To test this configuration and application, run the Docker environment using the following command:</p><pre>docker compose up</pre><p>After the Docker environment is up, send a CURL request to the Kafka connector to create a connector in Debezium for getting events from the MySQL database:</p><pre>curl -i -X PUT -H &quot;Content-Type:application/json&quot; \<br>  http://localhost:8083/connectors/source-debezium-orders-00/config \<br>  -d &#39;{<br>            &quot;connector.class&quot;: &quot;io.debezium.connector.mysql.MySqlConnector&quot;,<br>            &quot;database.hostname&quot;: &quot;mysql&quot;,<br>            &quot;database.port&quot;: &quot;3306&quot;,<br>            &quot;database.user&quot;: &quot;debezium&quot;,<br>            &quot;database.password&quot;: &quot;dbz&quot;,<br>            &quot;database.server.id&quot;: &quot;42&quot;,<br>            &quot;database.server.name&quot;: &quot;asgard&quot;,<br>            &quot;table.whitelist&quot;: &quot;demo.movies&quot;,<br>            &quot;database.history.kafka.bootstrap.servers&quot;: &quot;kafka:9092&quot;,<br>            &quot;database.history.kafka.topic&quot;: &quot;dbhistory.demo&quot; ,<br>            &quot;decimal.handling.mode&quot;: &quot;double&quot;,<br>            &quot;include.schema.changes&quot;: &quot;true&quot;,<br>            &quot;transforms&quot;: &quot;unwrap,dropTopicPrefix&quot;,<br>            &quot;transforms.unwrap.type&quot;: &quot;io.debezium.transforms.ExtractNewRecordState&quot;,<br>            &quot;transforms.dropTopicPrefix.type&quot;:&quot;org.apache.kafka.connect.transforms.RegexRouter&quot;,<br>            &quot;transforms.dropTopicPrefix.regex&quot;:&quot;asgard.demo.(.*)&quot;,<br>            &quot;transforms.dropTopicPrefix.replacement&quot;:&quot;$1&quot;,<br>            &quot;key.converter&quot;: &quot;io.confluent.connect.avro.AvroConverter&quot;,<br>            &quot;key.converter.schema.registry.url&quot;: &quot;http://schema-registry:8081&quot;,<br>            &quot;value.converter&quot;: &quot;org.apache.kafka.connect.json.JsonConverter&quot;,<br>            &quot;value.converter.schemas.enable&quot;: &quot;false&quot;<br>    }&#39;</pre><p>Also, don’t forget to run the kafka:consume command to consume Kafka events in the Laravel application:</p><pre>php artisan kafka:consume</pre><p>Now visit <a href="http://localhost:9000/">http://localhost:9000</a> to access Kafka manager UI.</p><h4>Conclusion</h4><p>Integrating Apache Kafka and the Debezium connector into a Laravel application opens up a world of possibilities for real-time data synchronization. In this tutorial, we explored the step-by-step process of setting up the development environment, configuring Kafka and the Debezium connector, consuming Kafka topics in Laravel, and monitoring and handling errors. By harnessing the power of Kafka and Debezium, you can achieve seamless real-time data synchronization in your Laravel projects, empowering your application with the latest and most accurate data.</p><h4>GitHub Repository</h4><p>If you’re eager to dive deeper into this topic and start implementing real-time data synchronization in your Laravel projects, I invite you to check out the accompanying GitHub repository:</p><p><a href="https://github.com/Balwant-Singh-Rathore/Laravel-Kafka-Event-Driven"><strong>https://github.com/Balwant-Singh-Rathore/Laravel-Kafka-Event-Driven</strong></a></p><p>This repository contains the complete code and configuration examples discussed in this tutorial.</p><blockquote><strong>For more updates on the latest tools and technologies, follow the </strong><a href="https://medium.com/simform-engineering"><strong>Simform Engineering</strong></a><strong> blog.</strong></blockquote><blockquote><strong>Follow Us: </strong><a href="https://twitter.com/simform"><strong>Twitter</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/simform/"><strong>LinkedIn</strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2506bc8f37a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/integrating-apache-kafka-in-laravel-real-time-database-synchronization-with-debezium-connector-2506bc8f37a7">Integrating Apache Kafka in Laravel: Real-time Database Synchronization with Debezium Connector</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Power of Laravel’s Service Container: A Practical Guide]]></title>
            <link>https://medium.com/simform-engineering/the-power-of-laravels-service-container-a-practical-guide-5efac941b94d?source=rss-9b66d1ff0bd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5efac941b94d</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[coding-patterns]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-service-container]]></category>
            <category><![CDATA[laravel-development]]></category>
            <dc:creator><![CDATA[Balwant Singh]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 07:59:34 GMT</pubDate>
            <atom:updated>2023-02-17T07:59:34.528Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Learn how to leverage the Service Container to manage class dependencies in your Larevel application easily.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIKEGxCFoSLiwX7n_0PwGA.jpeg" /><figcaption>image credit to the respective owner</figcaption></figure><p>If you’ve been working with Laravel for a while, you may have heard of the <strong>Service Container</strong>. But what is it, and how can you use it to take your Laravel projects to the next level?</p><p>In this tutorial, we will thoroughly explore the Service Container tool and show you how to use it to manage class dependencies in your Laravel application. Let’s start with a simple example and gradually refactor it into a more advanced example to show you how to harness the full power of the Service Container.</p><h4><strong>Getting Started with a Simple Example</strong></h4><p>Let’s start by creating a new controller and injecting a specific class into it. We will use a <strong>payment gateway</strong> as an example of a typical scenario where you need to charge a customer’s credit card or bank account when they place an order on your website</p><ol><li>Create a controller by running the following command:</li></ol><pre>php artisan make:controller PayOrderController</pre><p>2. Add a store() method to the controller and include a PaymentGateway dependency:</p><pre>namespace App\Http\Controllers;<br><br>use App\Billing\PaymentGateway;<br><br>class PayOrderController extends Controller<br>{<br>    public function store(PaymentGateway $paymentGateway)<br>    {<br>        // code to charge customer&#39;s account<br>    }<br>}</pre><p>3. Create a PaymentGateway class inside the app/Billing directory:</p><pre>namespace App\Billing;<br><br>class PaymentGateway<br>{<br>    public function charge($amount)<br>    {<br>        $bankResponse = [<br>            &#39;amount&#39; =&gt; $amount,<br>            &#39;confirmation_number&#39; =&gt; str_random(10),<br>        ];<br><br>        return $bankResponse;<br>    }<br>}</pre><p>4. Now you can use the $paymentGateway object inside the store() method to charge the customer&#39;s account:</p><pre>public function store(PaymentGateway $paymentGateway)<br>{<br>    $amount = 2500; // $25.00<br>    $bankResponse = $paymentGateway-&gt;charge($amount);<br><br>    return view(&#39;receipt&#39;, [<br>        &#39;amount&#39; =&gt; $bankResponse[&#39;amount&#39;],<br>        &#39;confirmation_number&#39; =&gt; $bankResponse[&#39;confirmation_number&#39;],<br>    ]);<br>}</pre><p>This is a simple example of how to use the Service Container tool in Laravel. However, as your project grows, you will find that managing class dependencies can become more complex. That’s when the Service Container really shines!</p><h4>Advanced Application of the Service Container</h4><p>Let’s take the above example and refactor it to <strong>utilize the Service Container more efficiently</strong>. We will use a ServiceProvider to register our PhonePayPaymentGateWay class, and add some additional functionality to demonstrate the flexibility of the Service Container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*-h7L7koj94EAuD3IQHxGWQ.gif" /><figcaption>credit to the respective image owner</figcaption></figure><ol><li>Create an PaymentGatewayInterface interface:</li></ol><pre>namespace App\Billing;<br><br>interface PaymentGatewayInterface<br>{<br>    public function charge($amount);<br>}</pre><p>2. Update the PhonePePaymentGateway class to implement the interface:</p><pre>namespace App\Billing;<br><br>class PhonePePaymentGateway implements PaymentGatewayInterface<br>{<br>    public function charge($amount){<br>       #phone pe payment gateway payment charge api implemtation<br>    }<br>}</pre><p>3. Create a PaymentGatewayServiceProvider class inside the app/Providers directory:</p><pre>namespace App\Providers;<br><br>use Illuminate\Support\ServiceProvider;<br>use App\Billing\PaymentGatewayInterface;<br>use App\Billing\PaymentGateway;<br><br>class PaymentGatewayServiceProvider extends ServiceProvider<br>{<br>    public function register()<br>    {<br>        $this-&gt;app-&gt;singleton(PaymentGatewayInterface::class, function ($app) {<br>            return new PhonePePaymentGateway();<br>        });<br>    }<br>}</pre><p>4. Add the PaymentGatewayServiceProvider to the providers array in your config/app.php file:</p><pre>&#39;providers&#39; =&gt; [<br>    // ...<br>    App\Providers\PaymentGatewayServiceProvider<br>]</pre><p>This registers the PaymentGatewayServiceProvider with Laravel, allowing it to use the Service Container to manage dependencies and inject instances of the PhonePePaymentGateway to a class where it’s needed.</p><p>Once you have added the provider, you can now access the PhonePePaymentGateway instance anywhere in your application by simply <strong>type-hinting</strong> it in the constructor of a class that needs it. For example:</p><pre>namespace App\Http\Controllers;<br><br>use App\Services\PaymentGateway;<br><br>class PaymentController extends Controller<br>{<br>    protected $paymentGateway;<br><br>    public function __construct(PaymentGatewayInterface $paymentGateway)<br>    {<br>        $this-&gt;paymentGateway = $paymentGateway;<br>    }<br><br>    public function store()<br>    {<br>        // use the payment gateway to process the payment<br>        $result = $this-&gt;paymentGateway-&gt;charge(2500);<br><br>        // handle the payment result<br>    }<br>}</pre><p>In this example, we inject an instance of the PaymentGatewayInterface into the PaymentController constructor. This is possible because we have registered PaymentGatewayServiceProvider with Laravel, which tells it how to create instances of the PhonePePayementGateway class.</p><p>With this setup, <strong>we can easily swap the implementation of the</strong> PaymentGateway class with a different one simply by updating the PaymentGatewayServiceProvider.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*XkQjm4gSF7EyJ3doSPHwrA.gif" /><figcaption>credit to the respective owner</figcaption></figure><p>Here is an example of how to proceed if we need to swap payment gateway:</p><pre>namespace App\Providers;<br><br>use Illuminate\Support\ServiceProvider;<br>use App\Billing\PaymentGatewayInterface;<br>use App\Billing\PaymentGateway;<br><br>class PaymentGatewayServiceProvider extends ServiceProvider<br>{<br>    public function register()<br>    {<br>        $this-&gt;app-&gt;singleton(PaymentGatewayInterface::class, function ($app) {<br>            return new GooglePayPaymentGateway();<br>        });<br>    }<br>}</pre><p>In this example, we are changing PaymentGatewayServiceProvider with a GooglePayPaymentGateway class.</p><p>And here is GooglePayPaymentGateway class:</p><pre>namespace App\Billing;<br><br>class GooglePayPaymentGateway implements PaymentGatewayInterface<br>{<br>    public function charge($amount){<br>       #googlepay payment gateway payment charge api implemtation<br>    }<br>}</pre><p>We can implement the rest of the functionality in our PaymentController for charge will be the same as implement, and there is no need to change it.</p><p>This is the power of the Laravel Service Container and why it is such an important part of the framework!</p><h4>Conclusion</h4><p>Laravel’s <a href="https://laravel.com/docs/9.x/container"><strong>Service Container</strong> </a>is an essential and powerful tool for managing class dependencies in your application. By using the Service Container, you can easily define how your classes should be instantiated, and Laravel takes care of the rest. This not only simplifies your code but also makes it more modular and maintainable. I hope this article helped you get a good understanding of the Service Container’s basic principles and how to use them in your Laravel projects. As you continue working with Laravel, you will likely find more ways to take advantage of the Service Container and improve your application’s architecture.</p><h4>Acknowledgments</h4><p>I would like to thank the Laravel community and the Laravel documentation team for their invaluable contributions to the Laravel ecosystem.</p><blockquote>Stay up to date with the latest trends in the development ecosystem by following <a href="https://medium.com/simform-engineering"><strong>Simform Engineering</strong></a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5efac941b94d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/the-power-of-laravels-service-container-a-practical-guide-5efac941b94d">The Power of Laravel’s Service Container: A Practical Guide</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Octane: Using Octane in the Laravel Framework]]></title>
            <link>https://medium.com/@balwantsingh37807/laravel-octane-using-octane-in-the-laravel-framework-3ef9849856d2?source=rss-9b66d1ff0bd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ef9849856d2</guid>
            <category><![CDATA[laravel-octane]]></category>
            <category><![CDATA[octane]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Balwant Singh]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 09:56:31 GMT</pubDate>
            <atom:updated>2023-02-04T09:56:31.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZjZBA2XEqEXdUIVZfNVLnw.jpeg" /><figcaption>The image is taken from <a href="https://pretzels.dev/en/blog/scaling-laravel-applications-with-octane">pretzels.dev</a></figcaption></figure><p>Laravel Octane is a high-performance, built-in web server for Laravel, designed to enhance the overall performance and scalability of Laravel applications. It is based on the popular Swoole PHP extension and provides a number of advanced features that make it a powerful choice for modern web development.</p><p>In this article, we will take a look at how to use Octane in a Laravel application and explore some of its advanced features.</p><h4>Getting Started:</h4><p>To use Octane in your Laravel application, you will need to install the Octane server. This can be done using the following command:</p><pre>composer require laravel/octane</pre><p>If you plan to use the Swoole application server to serve your Laravel Octane application, you must install the Swoole PHP extension. Typically, this can be done via PECL:</p><pre>pecl install swoole</pre><p>Once the Octane server and Swool is installed, you can start it using the following command:</p><pre>php artisan octane:start</pre><h4>Advanced Usage:</h4><blockquote>Running Concurrent Tasks:</blockquote><p>One of the key features of Laravel Octane is the ability to run multiple tasks concurrently. This allows you to process multiple requests at the same time, which can significantly increase the performance of your application.</p><p>Here is an example of how to run concurrent tasks in a Laravel Controller:</p><pre>use Laravel\Octane\Facades\Octane;<br><br>class ConcurrentTasksController extends Controller<br>{<br>    public function index()<br>    {<br>        [$users, $servers] = Octane::concurrently([<br>            fn () =&gt; User::all(),<br>            fn () =&gt; Server::all(),<br>        ]);<br><br>        return view(&#39;concurrent_tasks&#39;, compact(&#39;users&#39;, &#39;servers&#39;));<br>    }<br>}</pre><p>In this example, two tasks are run concurrently using the Octane::concurrently method. The User::all() and Server::all() methods are used to retrieve all records from the users and servers tables, respectively.</p><blockquote>Scheduling Ticks &amp; Intervals:</blockquote><p>Laravel Octane also provides the ability to schedule recurring tasks using the tick and interval methods.</p><p>Here is an example of how to schedule a recurring task in a Laravel Controller:</p><pre>use Laravel\Octane\Facades\Octane;<br><br>class TickerController extends Controller<br>{<br>    public function index()<br>    {<br>        Octane::tick(&#39;simple-ticker&#39;, fn () =&gt; echo(&#39;Ticking...&#39;))<br>                -&gt;seconds(10);<br><br>        return view(&#39;ticker&#39;);<br>    }<br>}</pre><blockquote>Managing Memory Leaks:</blockquote><p>Managing memory leaks can be a major challenge when working with long-running PHP applications. With Laravel Octane, you can easily mitigate this issue by using its built-in memory management features.</p><p>Here is an example of how you can monitor and manage memory usage in a Laravel Octane application:</p><pre>use App\Service;<br>use Illuminate\Http\Request;<br>use Illuminate\Support\Str;<br> <br>/**<br> * Handle an incoming request.<br> *<br> * @param  \Illuminate\Http\Request  $request<br> * @return void<br> */<br>public function index(Request $request)<br>{<br>    Service::$data[] = Str::random(10);<br> <br>    // ...<br>}</pre><h4>Conclusion:</h4><p>Laravel Octane is a powerful, high-performance web server for Laravel that provides a number of advanced features for modern web development. By leveraging its concurrent task support, tick and interval scheduling, and built-in cache, you can greatly enhance the performance and scalability of your Laravel applications. I hope this article has provided a useful introduction to using Octane in Laravel, and demonstrated some of its advanced features through example code. If you have any questions or feedback, please let me know in the comments below!</p><blockquote><em>Here you can learn more about the </em><a href="https://laravel.com/docs/9.x/octane">Laravel Octane</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef9849856d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Pipeline: Understanding and Implementing the Power of Pipelines]]></title>
            <link>https://medium.com/@balwantsingh37807/laravel-pipeline-understanding-and-implementing-the-power-of-pipelines-7d6939dd4db9?source=rss-9b66d1ff0bd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d6939dd4db9</guid>
            <category><![CDATA[laravel-middleware]]></category>
            <category><![CDATA[laravel-pipeline]]></category>
            <category><![CDATA[laravel-tips-and-tricks]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <dc:creator><![CDATA[Balwant Singh]]></dc:creator>
            <pubDate>Thu, 02 Feb 2023 06:38:21 GMT</pubDate>
            <atom:updated>2023-02-02T07:11:52.253Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_PUoPeuiMAxNY95-ve7AQ.png" /><figcaption>Image is taken from <a href="https://www.freepik.com/free-vector/plumber-service-concept_2869860.htm">freepik</a></figcaption></figure><p>Laravel, a popular PHP framework for web application development, comes equipped with a powerful tool known as middleware. Middleware acts as a bridge between the request and response of an application and can perform various tasks such as authentication, request validation, and logging.</p><blockquote>The beauty of Laravel’s pipeline is that it allows developers to encapsulate functionality into reusable, independent units. This modular approach makes it easy to maintain and extend your application.</blockquote><p>Let’s dive into a practical example to understand the pipeline in action</p><p>In Laravel, pipelines provide a simple and elegant way to process data through several stages, allowing you to filter, transform, and manipulate the data before presenting it to the user. In this article, we’ll take a closer look at how to use Laravel pipelines, focusing on how to use a single pipe to filter data.</p><h4><strong>Here’s an example of how to use pipe in Laravel</strong>:</h4><pre>use Illuminate\Pipeline\Pipeline;<br><br>app(Pipeline::class)<br>-&gt;send(Product::all())<br>-&gt;through([<br>    Quantity::class,<br>    Status::class<br>])<br>-&gt;via(‘customMethodName’)  // &lt;---- if you Want to modify in you custom method :)<br>-&gt;thenReturn();  // Returnig Data<br><br><br># also we can use somthig like this for creating product : <br>app(Pipeline::class)<br> -&gt;send($content)<br> -&gt;through($pipes)<br> -&gt;then(function ($content) {<br>   return Product::create([&#39;content&#39; =&gt; $content]);<br> });</pre><p>In this example, we first retrieve all of the records from the model using the all method. The send the method is used to pass the data to the pipeline, which is then processed through the Quantity and Statuspipes. The Quantity pipe implements a handle method, which takes the data and performs the necessary transformations and filters.</p><figure><img alt="Data processed through the Pipes" src="https://cdn-images-1.medium.com/max/400/1*r68h9YF4VxavnzIQjdAdkQ.gif" /><figcaption>Image Credit : <a href="https://medium.com/u/b2c7a6c2542b">Dribbble</a></figcaption></figure><p>Here’s an example of what the Quantity pipe might look like:</p><pre>class Quantity<br>{<br>    public function handle($products, Closure $next)<br>    {<br>        if (!request()-&gt;has(&#39;quantity&#39;)) {<br>            return $next($products);<br>        }<br><br>        $qty = request(&#39;quantity&#39;);<br>        return $next($products)-&gt;whereBetween(&#39;quantity&#39;, [$qty-&gt;min, $qty-&gt;max]);<br>    }<br>}</pre><p>Here’s an example of what the Status pipe might look like:</p><pre>class Status<br>{<br>    public function handle($products, Closure $next)<br>    {<br>        if (!request()-&gt;has(&#39;status&#39;)) {<br>            return $next($products);<br>        }<br>        return $next($products)-&gt;whereIn(&#39;status&#39;, request(&#39;status&#39;));<br>    }<br>}</pre><p>In this both examples, the Quantity and Statuspipes filters if the products query has the required parameter then we apply the where conditions. If the request doesn&#39;t have a parameter then products are passed to the next stage of the pipeline using the $next closure.</p><p>Laravel pipelines are a powerful tool for filtering and manipulating data, providing a simple and organized way to process data through a series of stages. By using pipes, you can encapsulate filtering logic into reusable components, making it easy to reuse the same filtering logic in multiple parts of your application.</p><h3>Conclusion:</h3><p>In conclusion, Laravel pipelines provide a clean and organized way to filter and manipulate data in your web application. Whether you’re using a single pipe or a series of pipes, Laravel pipelines make it easy to process data in an organized and maintainable way.</p><blockquote>Here you can learn more about the <a href="https://laracasts.com/series/whip-monstrous-code-into-shape/episodes/14">Laravel Pipelines</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d6939dd4db9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>