<?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: Hallo Rzgar</title>
    <description>The latest articles on DEV Community by Hallo Rzgar (@hallorzgar).</description>
    <link>https://dev.to/hallorzgar</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%2F995779%2F009c74a7-4d70-4179-9a60-6d61f61f565e.jpg</url>
      <title>DEV Community: Hallo Rzgar</title>
      <link>https://dev.to/hallorzgar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hallorzgar"/>
    <language>en</language>
    <item>
      <title>Understanding Object Storage: A Comprehensive Guide</title>
      <dc:creator>Hallo Rzgar</dc:creator>
      <pubDate>Thu, 18 Apr 2024 11:55:09 +0000</pubDate>
      <link>https://dev.to/hallorzgar/understanding-object-storage-a-comprehensive-guide-2oln</link>
      <guid>https://dev.to/hallorzgar/understanding-object-storage-a-comprehensive-guide-2oln</guid>
      <description>&lt;p&gt;In today's rapidly evolving data storage landscape, object storage has emerged as a popular choice among developers, IT professionals, and organizations. It's essential to understand what object storage is, its advantages, the available options, and when it's the ideal solution. This article aims to simplify and shed light on object storage.&lt;/p&gt;

&lt;p&gt;Our lives de­pend on data storage systems. Obje­ct storage is becoming popular very fast. It's important for te­chnology workers to understand object storage­, its good points, available choices, and when it's the­ best option. This post explains object storage­ easily, showing its main traits and real uses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Object Storage?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;imagine yourse­lf working with storage like unique boxe­s, tagged differently, inste­ad of rigid cabinets or blocks. That's object storage - it tre­ats data as separate "objects", bundle­d with metadata and identifiers. You acce­ss these objects through we­b calls over networks, making manageme­nt effortless.&lt;br&gt;
Object storage­ has a straightforward design - no complicated folder tre­es, just an expanse whe­re each object e­xists independently. This simplicity allows scalability, ide­al for managing massive amounts of varied, unstructured data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Object Storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt; &lt;br&gt;
Object storage­ grows easily, built to handle huge amounts of data—imagine­ exabytes—without struggling like re­gular file systems could under similar stre­ss. It's fantastic for cloud storage, where de­mands can spike suddenly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Durability and Availability&lt;/strong&gt;&lt;br&gt;
Data fortresse­s shield important info. Copies are spre­ad across many places and gadgets. If one part bre­aks down, your data's still totally accessible, complete­ly safe and sound.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost-Effectiveness&lt;/strong&gt;&lt;br&gt;
Can eve­ryday materials give storage? Ye­s! Unlike costly disk options, object storage is e­conomical. Low-cost items are used. Le­ss maintenance occurs, too, which helps budge­ts. Overall, it's a money-saving choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Metadata and Customization&lt;/strong&gt;&lt;br&gt;
Object me­tadata enables thorough descriptions, facilitating data manage­ment. This simplifies organizing and retrie­ving information, permitting storage solutions customized to particular re­quirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Management Features&lt;/strong&gt;&lt;br&gt;
Version control, life­cycle management, and acce­ss settings are built-in tools. Togethe­r, they allow for complex data manageme­nt right within the storage layer. The­ strategies are sophisticate­d and integrated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Object Storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Object storage comes in two main flavors:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Public Cloud Object Storage:&lt;br&gt;
Giants like Amazon S3, Google Cloud Storage, and Microsoft Azure Blob Storage offer scalable storage on a flexible, pay-as-you-go basis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Private Cloud Object Storage:&lt;br&gt;
Systems like OpenStack Swift and MinIO let organizations run their own object storage, keeping data in-house while still enjoying all the perks of the technology.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;When and Why We Need Object Storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Object storage­ shines brightly when dealing with massive­ amounts of unstructured data that require storage­ and access, yet seldom unde­rgo modifications.  This includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Web and Mobile Applications:&lt;br&gt;
Perfect for storing all sorts of media that lights up our screens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data Archiving:&lt;br&gt;
Ideal for keeping records and backups safe and sound over the long haul.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Big Data and Analytics:&lt;br&gt;
A boon for platforms swimming in data lakes, needing scalable and flexible storage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IoT Systems:&lt;br&gt;
Capable of handling the data deluge from countless IoT devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Object storage­ isn't only a tool. It's an efficient helpe­r for dealing with lots of messy data. It can grow, last long, and save mone­y. This makes it great for many uses, e­specially when storing data for a long time is crucial. As more­ digital stuff piles up, knowing about object storage and using it we­ll is important. Companies focused on data nee­d it, whether working online or from the­ir own centers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Uploading Files to S3 or a Similar Server in Laravel</title>
      <dc:creator>Hallo Rzgar</dc:creator>
      <pubDate>Sun, 02 Jul 2023 06:00:45 +0000</pubDate>
      <link>https://dev.to/hallorzgar/uploading-files-to-s3-or-a-similar-server-in-laravel-1lb6</link>
      <guid>https://dev.to/hallorzgar/uploading-files-to-s3-or-a-similar-server-in-laravel-1lb6</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Uploading files to cloud storage services like Amazon S3 is a common requirement for many Laravel applications. In this article, we'll explore how to upload files to an S3 bucket using Laravel and the AWS SDK for PHP. We'll also cover generating pre-signed URLs for accessing the uploaded files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Before we begin, make sure you have the following prerequisites in place:&lt;/p&gt;

&lt;p&gt;1-Laravel installed on your system.&lt;br&gt;
2-AWS account with S3 bucket credentials.&lt;br&gt;
3-AWS SDK for PHP installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set Up the AWS SDK for PHP&lt;/strong&gt;&lt;br&gt;
To get started, install the AWS SDK for PHP in your Laravel project. Use Composer to install the SDK by running the following command in your project root directory:&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 aws/aws-sdk-php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Configure Laravel Environment Variables&lt;/strong&gt;&lt;br&gt;
Next, open your Laravel project's .env file and add the following environment variables&lt;br&gt;
and if you have endpoint also add it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your-s3-bucket-name
AWS_ENDPOINT=your-s3-endpoint (e.g., https://s3.your-region.amazonaws.com)
AWS_USE_PATH_STYLE_ENDPOINT=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Implement the File Upload Functionality&lt;/strong&gt;&lt;br&gt;
In your Laravel application, create a new controller or use an existing one. Let's assume you have a controller called S3Controller. Inside the controller, add the following code:&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 Aws\S3\S3Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class S3Controller extends Controller
{
    public function uploadFile(Request $request)
    {
        $file = $request-&amp;gt;file('my_file');
        $bucket = env('AWS_BUCKET');
        $expiry = '+5 minutes'; // Expiration time for the URL

        $path = Storage::disk('s3')-&amp;gt;put('folder-name', $file);

        // Set the visibility of the uploaded file to public
        Storage::disk('s3')-&amp;gt;setVisibility($path, 'public');


        // Generate a pre-signed URL for the uploaded file
       $s3Client = new S3Client([
            'credentials' =&amp;gt; [
                'key' =&amp;gt; env('AWS_ACCESS_KEY_ID'),
                'secret' =&amp;gt; env('AWS_SECRET_ACCESS_KEY'),
            ],
            'region' =&amp;gt; 'us-east-1',
            'version' =&amp;gt; 'latest',
            'endpoint' =&amp;gt; env('AWS_ENDPOINT'),
            'use_path_style_endpoint' =&amp;gt; 
            env('AWS_USE_PATH_STYLE_ENDPOINT'),
        ]);

        $command = $s3Client-&amp;gt;getCommand('GetObject', [
            'Bucket' =&amp;gt; $bucket,
            'Key' =&amp;gt; $path,
        ]);


        $signedUrl = $s3Client
           -&amp;gt;createPresignedRequest($command, $expiry)
           -&amp;gt;getUri();

        return $signedUrl;
    }


// the function for get the file after upload

    public function get(Request $request)
    {

    // Specify the key and bucket name of the S3 object

   // $key must be like that get from request or database   
  //$key='foldernameA6Hlt7uyoZUpqsfIpeEpT7YRgKJ9JLGRMfnXuyRw.jpg';

        $key= $request-&amp;gt;file('my_file');
        $bucket = env('AWS_BUCKET');
        $expiry = '1 minutes'; // Expiration time for the URL

        // Instantiate the S3 client
        $s3Client = new S3Client([
            'credentials' =&amp;gt; [
                'key' =&amp;gt; env('AWS_ACCESS_KEY_ID'),
                'secret' =&amp;gt; env('AWS_SECRET_ACCESS_KEY'),
            ],
            'region' =&amp;gt; 'us-east-1',
            'version' =&amp;gt; 'latest',
            'endpoint' =&amp;gt; env('AWS_ENDPOINT'),
            'use_path_style_endpoint' =&amp;gt; 
            env('AWS_USE_PATH_STYLE_ENDPOINT'),
        ]);
        $command = $s3Client-&amp;gt;getCommand('GetObject', [
            'Bucket' =&amp;gt; $bucket,
            'Key' =&amp;gt; $key,
        ]);
        $signedUrl = $s3Client
        -&amp;gt;createPresignedRequest($command, $expiry)
        -&amp;gt;getUri();

        return $signedUrl;


    }
}

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

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The uploadFile method handles the file upload functionality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It retrieves the uploaded file from the request and stores it in &lt;br&gt;
the specified S3 bucket under the "folder-name" directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The visibility of the uploaded file is set to public, allowing &lt;br&gt;
public access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The $url variable contains the full URL of the uploaded file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The $signedUrl variable contains a pre-signed URL for accessing &lt;br&gt;
the uploaded file, valid for a specific duration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The get method retrieves the pre-signed URL for a specific file stored in the S3 bucket. It specifies the key and bucket name of the S3 object and generates a pre-signed URL using the AWS SDK.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this article, we learned how to upload files to an S3 bucket in Laravel using the AWS SDK for PHP. We also explored how to generate pre-signed URLs for accessing the uploaded files. By following the steps outlined in this article, you can easily integrate file upload functionality with S3 or a similar server in your Laravel applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Leveraging Laravel WebSockets : A Practical Guide</title>
      <dc:creator>Hallo Rzgar</dc:creator>
      <pubDate>Thu, 15 Jun 2023 09:38:53 +0000</pubDate>
      <link>https://dev.to/hallorzgar/leveraging-laravel-websockets-a-practical-guide-5f4l</link>
      <guid>https://dev.to/hallorzgar/leveraging-laravel-websockets-a-practical-guide-5f4l</guid>
      <description>&lt;p&gt;In this tutorial, we will explore the concept of WebSocket API or WebSockets and its significance in real-time applications. Unlike traditional HTTP requests, WebSocket provides a two-way communication channel between the server and the client.&lt;/p&gt;

&lt;p&gt;When using Ajax (Axios, Fetch), we can send and receive data from the server without reloading the page. However, this approach relies on one-way communication, where the server cannot send data to the client without a prior request. This limitation becomes evident in scenarios like an Ajax chat application, where we constantly need to send requests to check for new messages.&lt;/p&gt;

&lt;p&gt;To overcome this challenge, WebSockets come into play by establishing a persistent, interactive connection session between the server and the user's webpage. This connection allows for continuous communication, resembling a phone call between the server and the browser. Once initiated, the server can send messages or objects to the webpage at any time, without the need for repetitive polling.&lt;/p&gt;

&lt;p&gt;By leveraging WebSockets, we can create real-time applications where the server can instantly send data to the webpage. For example, consider the Facebook notification system that informs users about post likes. When someone likes a post, the server triggers a like event and promptly sends a WebSocket message notification, such as "Someone likes your post."&lt;/p&gt;

&lt;p&gt;Through this tutorial, we will explore how to set up a Laravel WebSockets server, enabling real-time functionality using Laravel 9. Stay tuned for a step-by-step example and practical implementation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Laravel WebSocket concept&lt;/strong&gt;&lt;br&gt;
In Laravel, the concept of WebSockets revolves around creating channels and broadcasting events to provide real-time, live-updating user interfaces. Here's a breakdown of the Laravel WebSocket concept:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1-Channel Creation&lt;/strong&gt;: In Laravel, you can define channels in the routes/channels.php file. These channels act as communication pathways between the server and clients.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2-Broadcasting Events&lt;/strong&gt;: To send real-time updates, you can broadcast Laravel events on specific channels. When an event is triggered, the message associated with it will be sent to all clients subscribed to that particular channel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3-Subscribing to Channels&lt;/strong&gt;: Clients, typically web browsers, can subscribe to specific channels to receive messages sent by the server. This allows for real-time updates without the need for constant polling.&lt;/p&gt;

&lt;p&gt;We can install Laravel-websockets package via 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 require beyondcode/laravel-websockets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package comes with migration to save statistical information about the running WebSockets server.&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 vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And publish the WebSocket configuration file&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 pusher/pusher-php-server "~3.0"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to make our BROADCAST_DRIVER to be pusher in .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;BROADCAST_DRIVER=pusher
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To configure Pusher for Laravel WebSockets in the config/broadcasting.php file, you can modify the configuration as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        'pusher' =&amp;gt; [
            'driver' =&amp;gt; 'pusher',
            'key' =&amp;gt; env('PUSHER_APP_KEY'),
            'secret' =&amp;gt; env('PUSHER_APP_SECRET'),
            'app_id' =&amp;gt; env('PUSHER_APP_ID'),
            'options' =&amp;gt; [
                'cluster' =&amp;gt; env('PUSHER_APP_CLUSTER'),
                'host' =&amp;gt; env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
                'port' =&amp;gt; env('PUSHER_PORT', 443),
                'scheme' =&amp;gt; env('PUSHER_SCHEME', 'https'),
                'encrypted' =&amp;gt; true,
                'useTLS' =&amp;gt; env('PUSHER_SCHEME', 'https') === 'https',
            ],
            'client_options' =&amp;gt; [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and in .ENV add pusher app key ,secret ,host , port , schema and cluster&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PUSHER_APP_ID=local
PUSHER_APP_KEY=local
PUSHER_APP_SECRET=local
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=http
PUSHER_APP_CLUSTER=mt1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now we can use WebSockets&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 websockets:serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and in different terminal run laravel server and go &lt;br&gt;
&lt;a href="http://127.0.0.1:8000/laravel-websockets"&gt;http://127.0.0.1:8000/laravel-websockets&lt;/a&gt;&lt;br&gt;
to see dashboard&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;&lt;strong&gt;Broadcasting Laravel Event on a public channel&lt;/strong&gt;&lt;br&gt;
To enable our server to send messages to the client in a public channel that doesn't require authentication, we'll begin by creating an event. This event will serve as a trigger for broadcasting messages.&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:event PublicMessageEvent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To broadcast our event using the ShouldBroadcast interface, we need to implement it in our event class (app\Events\PublicMessageEvent.php in your example). This interface provides the necessary methods to broadcast the event and specify the channel to broadcast on.&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\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\Http\Traits\WebSocketsTrait;


class PublicMessageEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels,WebSocketsTrait;

    /**
     * Create a new event instance.
     */
    public $data;
    public function __construct()
    {
        //
    }



    /**
     * Get the channels the event should broadcast on.
     *
     * @return array&amp;lt;int, \Illuminate\Broadcasting\Channel&amp;gt;
     */
    public function broadcastOn()
    {
        $this-&amp;gt;data = $this-&amp;gt;status();

        return [
            new Channel('public'),
        ];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, the event will be stored in a queue job but if you want to broadcast immediately use ShouldBroadcastNow interface.&lt;/p&gt;

&lt;p&gt;and in web add that route&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('/status', [\App\Http\Controllers\WebSocket::class, 'status']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can broadcast the event and create method in controller&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 App\Events\PublicMessageEvent;
use Illuminate\Http\Request;

class WebSocket extends Controller
{
    public function status () {
         broadcast(new PublicMessageEvent());
    }
}

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

&lt;/div&gt;



&lt;p&gt;I utilize the WebSocketsTrait to broadcast messages, eliminating the need to navigate to a specific channel.&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\Traits;

use App\Models\User;

trait WebSocketsTrait
{
    public function status()
    {

        return User::all();
    }


}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notice you don’t have to declare a public channel in routes\channels.php&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;now all things look fine &lt;/p&gt;

&lt;p&gt;To begin, follow these steps to open the Laravel WebSockets dashboard and establish a connection:&lt;br&gt;
&lt;strong&gt;1-open the Laravel websockets dashboard&lt;/strong&gt; &lt;a href="http://127.0.0.1:8000/laravel-websockets"&gt;http://127.0.0.1:8000/laravel-websockets&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2-click connect button and make sure you use the port 6001&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
then in another browser tab go to &lt;a href="http://127.0.0.1:8000/status"&gt;http://127.0.0.1:8000/status&lt;/a&gt;&lt;br&gt;
you should see all Users .&lt;br&gt;
you can see channel name and the event name as well in  api-message in WebSockets dashboard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To listen for the event broadcasted from the Laravel backend in frontend frameworks like Vue, React, or any other framework, you can utilize Laravel Echo. Laravel Echo is a JavaScript library that simplifies the process of subscribing to channels and listening for events.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CONCLUSION&lt;/strong&gt;&lt;br&gt;
In conclusion, by integrating Laravel WebSockets into your backend infrastructure, you can unlock the potential of real-time communication between the server and the client. Leveraging WebSockets allows you to establish persistent connections, enabling bidirectional data flow and facilitating the development of dynamic and interactive applications. By following the steps outlined in this tutorial, you'll have the foundation to implement Laravel WebSockets and leverage its power in your backend architecture. Happy coding!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>tutorial</category>
      <category>websockets</category>
    </item>
    <item>
      <title>Laravel Security</title>
      <dc:creator>Hallo Rzgar</dc:creator>
      <pubDate>Fri, 17 Feb 2023 12:12:58 +0000</pubDate>
      <link>https://dev.to/hallorzgar/laravel-security-58d3</link>
      <guid>https://dev.to/hallorzgar/laravel-security-58d3</guid>
      <description>&lt;p&gt;Laravel is one of the most popular PHP frameworks, known for its simplicity, elegance, and robustness. Laravel has been built with security in mind, and its framework includes many features that can help you deploy your application more securely. In this article, we will discuss some of the key security concerns when deploying Laravel applications, and we will provide code examples of how to mitigate them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Deploying Securely&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deploying your Laravel application securely is critical. The first step is to ensure that your server is up-to-date with the latest security patches. Next, make sure that you have set up HTTPS properly. HTTPS is essential for securing data transmission between your application and your users. To set up HTTPS, you will need to obtain an SSL certificate and configure your web server to use it.&lt;/p&gt;

&lt;p&gt;Another key aspect of deploying securely is to protect sensitive files and directories on your server. Laravel comes with a .htaccess file that can help you restrict access to certain directories. You should also set appropriate file permissions to ensure that only authorized users can access files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Missing Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most common security vulnerabilities in web applications is missing authorization. Laravel provides built-in mechanisms for handling authentication and authorization, such as middleware and guards. Middleware can be used to restrict access to certain routes, while guards can be used to authenticate users based on different drivers, such as session or token-based authentication.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use middleware to protect a route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('/dashboard', function () {
    // Only authenticated users can access this route
})-&amp;gt;middleware('auth');

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

&lt;/div&gt;



&lt;p&gt;And here is an example of how to use a guard to authenticate a user based on a token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (Auth::guard('api')-&amp;gt;check()) {
    // The user is authenticated via an API token
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. User Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User input is a common source of security vulnerabilities, such as cross-site scripting (XSS) and SQL injection. To prevent XSS, Laravel provides a Blade template engine that automatically escapes user input. To prevent SQL injection, you should use parameterized queries when interacting with your database. Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$users = DB::select('SELECT * FROM users WHERE id = ?', [$id]);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Markdown Security Concerns&lt;/strong&gt;&lt;br&gt;
Markdown is a popular syntax for writing formatted text, but it can also be a security concern. Markdown can include HTML, which can lead to XSS vulnerabilities. To mitigate this, Laravel provides a Markdown engine that can sanitize HTML input. Here is an example of how to use the Laravel Markdown engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ Illuminate\Mail\Markdown::parse($text) }}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Sensitive Attributes&lt;/strong&gt;&lt;br&gt;
Sensitive attributes, such as passwords, should be hashed before storing them in the database. Laravel provides a built-in hashing mechanism that can be used to hash passwords. Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$hashedPassword = Hash::make($password);

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

&lt;/div&gt;



&lt;p&gt;Additionally, you should encrypt sensitive data using Laravel's encryption facilities. Here's an example of how to encrypt and decrypt data in Laravel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$encryptedData = encrypt('sensitive data');
$decryptedData = decrypt($encryptedData);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Rate Limiting is a Must&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rate limiting is an essential feature for preventing brute force attacks and DoS attacks. Laravel provides a built-in rate limiting feature that can be used to limit the number of requests from a single IP address. Here is an example of how to use Laravel's rate limiting feature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware('throttle:60,1')-&amp;gt;group(function () {
    // This route can be accessed 60 times per minute per IP address
});

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

&lt;/div&gt;



&lt;p&gt;In conclusion, Laravel is a secure and robust framework, but it still requires careful attention to security when deploying your application. By following best practices and using the built-in security features of Laravel, you can deploy a secure and reliable web application.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>security</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Optimizing Laravel Performance ?</title>
      <dc:creator>Hallo Rzgar</dc:creator>
      <pubDate>Tue, 31 Jan 2023 09:29:25 +0000</pubDate>
      <link>https://dev.to/hallorzgar/how-to-optimizing-laravel-performance--13ac</link>
      <guid>https://dev.to/hallorzgar/how-to-optimizing-laravel-performance--13ac</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Optimizing in Laravel ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Refers to the process of making improvements to the speed, efficiency and scalability of a Laravel application. This can be achieved by reducing the amount of resources required by the application, minimizing the number of database queries, and using caching to store frequently used data. Other techniques for optimizing Laravel performance include using pagination, enabling gzip compression, using a content delivery network (CDN), and profiling the application to identify and resolve performance bottlenecks.&lt;/p&gt;

&lt;p&gt;It's important to think about performance optimization. Here are Some tips and tricks to help you improve the performance of your Laravel application:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1- Caching&lt;/strong&gt;: Laravel provides several caching mechanisms, including view caching, route caching, and model caching. By using these mechanisms, you can store the results of expensive database queries or calculations so that you don't have to perform them every time a user requests a page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- Optimizing database queries&lt;/strong&gt;: Laravel's Eloquent ORM makes it easy to perform database queries, but it's important to make sure your queries are optimized. Consider using indexing to speed up your queries, and limit the number of records returned by a query to only what you need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3- Minimizing the number of database connections&lt;/strong&gt;: Laravel uses database connections to interact with your database, but having too many connections can slow down your application. You can minimize the number of connections by pooling them, or by using a connection manager like PDO.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4- Using pagination&lt;/strong&gt;: Laravel provides built-in support for pagination, which allows you to split a large number of records into smaller, more manageable chunks. By using pagination, you can reduce the amount of data that needs to be transferred between the server and the client, which can help improve performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5- Optimizing images&lt;/strong&gt;: Large images can slow down your application, so it's important to optimize them. Consider compressing your images, and using image optimization tools to reduce their file size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6- Enabling gzip compression&lt;/strong&gt;: Gzip compression compresses your HTML, CSS, and JavaScript files, which can help reduce the size of the data that needs to be transferred over the network. Laravel provides an easy way to enable gzip compression in your application, so consider doing this if your application is not already using it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7- Profiling your application&lt;/strong&gt;: Laravel provides a built-in profiler that you can use to identify performance bottlenecks in your application. The profiler provides information about database queries, memory usage, and other performance metrics, which can help you identify areas of your application that need optimization.&lt;/p&gt;

&lt;p&gt;By following these tips and tricks, you can help improve the performance of your Laravel application, making it faster and more responsive for your users.&lt;/p&gt;

&lt;p&gt;Sure, here are a few examples to illustrate each of the tips and tricks mentioned in the previous article:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1-Caching&lt;/strong&gt;: In Laravel, you can cache the results of an expensive database query or calculation using the Cache facade. For example:&lt;br&gt;
&lt;/p&gt;

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

$results = Cache::remember('key', $minutes, function () {
    return DB::table('table')-&amp;gt;get();
});

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2-Optimizing database queries&lt;/strong&gt;: When using Eloquent, you can use eager loading to reduce the number of database queries. For example:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3-Minimizing the number of database connections:&lt;/strong&gt; You can pool database connections in Laravel by using a connection manager like PDO. For example:&lt;br&gt;
&lt;/p&gt;

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

$pdo = DB::connection()-&amp;gt;getPdo();

$statement = $pdo-&amp;gt;prepare('SELECT * FROM users');

$statement-&amp;gt;execute();

$results = $statement-&amp;gt;fetchAll();

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4- Using pagination&lt;/strong&gt;: In Laravel, you can use the &lt;code&gt;paginate&lt;/code&gt; method to easily paginate your database results. For example:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5- Optimizing images&lt;/strong&gt;: In Laravel, you can use a package like Intervention Image to optimize your images. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Intervention\Image\Facades\Image;

$image = Image::make('public/image.jpg')-&amp;gt;resize(320, 240)-&amp;gt;save('public/image-optimized.jpg');

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6- nabling gzip compression&lt;/strong&gt;: In Laravel, you can enable gzip compression by adding the following to your .htaccess 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;IfModule mod_deflate.c&amp;gt;
  AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/javascript
  &amp;lt;IfModule mod_setenvif.c&amp;gt;
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  &amp;lt;/IfModule&amp;gt;
&amp;lt;/IfModule&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7- Profiling your application&lt;/strong&gt;: In Laravel, you can use the built-in profiler to profile your application. To do this, simply add the following to the end of your .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;APP_DEBUG=true

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
optimizing Laravel performance is an important task for ensuring a fast, efficient, and scalable Laravel application. The techniques for optimizing Laravel performance can vary depending on the specifics of the application, by implementing those techniques and continually monitoring the performance of the application, developers can ensure that Laravel applications perform optimally and provide a positive experience for users.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Why Laravel 🤔 ??</title>
      <dc:creator>Hallo Rzgar</dc:creator>
      <pubDate>Mon, 16 Jan 2023 13:29:40 +0000</pubDate>
      <link>https://dev.to/hallorzgar/why-laravel--2gji</link>
      <guid>https://dev.to/hallorzgar/why-laravel--2gji</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is laravel&lt;/strong&gt; ?&lt;br&gt;
Laravel is a PHP based web-framework for building&lt;br&gt;
high-end web applications using its significant and&lt;br&gt;
graceful syntaxes. Laravel was developed by Taylor&lt;br&gt;
Otwell in July 2011 and it was released more than five&lt;br&gt;
years after the release of the Codeigniter. It comes with&lt;br&gt;
a strong collection of tools and provides application&lt;br&gt;
architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it work&lt;/strong&gt;&lt;br&gt;
Laravel use MVC &lt;br&gt;
MVC is a short form for ‘Model&lt;br&gt;
View Controller’. This illustrates the use of structure&lt;br&gt;
developers when constructing applications. MVC basically is&lt;br&gt;
a software which separates utility/domain/commercial&lt;br&gt;
enterprise in terms of the interface of customers. This is done&lt;br&gt;
by breaking MVC software into the further three parts: first&lt;br&gt;
is the Model, second is the View, and the last one is the&lt;br&gt;
Controller. The model handles basic machine behaviours and&lt;br&gt;
information. It answers to instructions to change the status of&lt;br&gt;
its documents and also to alert observers of periodic systems&lt;br&gt;
when the facts change. This may be a database or a retrieval&lt;br&gt;
device. So, in short, this is the record-management of the&lt;br&gt;
programme or software. View correctly provides the&lt;br&gt;
software's user interface feature and display information into&lt;br&gt;
a form via a model which is sufficient for the interface of the&lt;br&gt;
user. The controller gets the data request from the user and&lt;br&gt;
passes it to the model objects and sees the execution of&lt;br&gt;
appropriate actions.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;8 Benefits of Laravel Framework&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's quick and simple.&lt;/li&gt;
&lt;li&gt;Security is key.&lt;/li&gt;
&lt;li&gt;Better website performance.&lt;/li&gt;
&lt;li&gt;Great for Traffic-Handling.&lt;/li&gt;
&lt;li&gt;Really Flexible.&lt;/li&gt;
&lt;li&gt;Easy third-party integrations.&lt;/li&gt;
&lt;li&gt;Simple Website Maintenance.&lt;/li&gt;
&lt;li&gt;The cost of a Laravel Site.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Some Features of Laravel&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication.&lt;/li&gt;
&lt;li&gt;Innovative Template Engine.&lt;/li&gt;
&lt;li&gt;Effective ORM.&lt;/li&gt;
&lt;li&gt;MVC Architecture Support.&lt;/li&gt;
&lt;li&gt;Secure Migration System.&lt;/li&gt;
&lt;li&gt;Unique Unit-testing.&lt;/li&gt;
&lt;li&gt;Intact Security.&lt;/li&gt;
&lt;li&gt;Libraries and Modular.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Laravel Packages Which You Can Use to Optimize App&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spatie.&lt;/li&gt;
&lt;li&gt;Laravel Debugbar.&lt;/li&gt;
&lt;li&gt;Laravel User Verification.&lt;/li&gt;
&lt;li&gt;Socialite.&lt;/li&gt;
&lt;li&gt;Migration Generator.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
