<?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: David</title>
    <description>The latest articles on DEV Community by David (@davidgualvez).</description>
    <link>https://dev.to/davidgualvez</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%2F596842%2Faf367bef-73d0-4c2a-aa2e-82a220d0d749.jpeg</url>
      <title>DEV Community: David</title>
      <link>https://dev.to/davidgualvez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidgualvez"/>
    <language>en</language>
    <item>
      <title>How to run SQL Server on M1/M2 with Docker</title>
      <dc:creator>David</dc:creator>
      <pubDate>Fri, 05 Jul 2024 09:20:29 +0000</pubDate>
      <link>https://dev.to/davidgualvez/how-to-run-sql-server-on-m1m2-with-docker-3f9n</link>
      <guid>https://dev.to/davidgualvez/how-to-run-sql-server-on-m1m2-with-docker-3f9n</guid>
      <description>&lt;p&gt;Pull the image by opening up a terminal and running the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull mcr.microsoft.com/azure-sql-edge`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=your_strong_password' -p 1433:1433 --name azuresqledge -d -v sqlvolume:/var/opt/mssql mcr.microsoft.com/azure-sql-edge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;–cap-add SYS_PTRACE&lt;/strong&gt; – here is Microsoft’s note on this line: The --cap-add SYS_PTRACE flag is required for non-root SQL Server containers to generate dumps for troubleshooting purposes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-e ‘ACCEPT_EULA=1’&lt;/strong&gt; is an environment variable, which is saying that we will accept the End User License Agreement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-e ‘MSSQL_SA_PASSWORD=your_strong_password’&lt;/strong&gt; – this is setting the password for the sa (the system administrator) user. This is how you will log into the database. By default the username is ‘sa’.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-p 1433:1433&lt;/strong&gt; is mapping ports. The left side of the colon is the port on the host (your mac). The right side is the port used inside the container&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;–name azuresqledge&lt;/strong&gt; is just giving the container a more user-friendly name after it starts running&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-d&lt;/strong&gt; is detached mode. This means that the terminal won’t attach to the process, which means it’ll start the container up and then give you terminal control back, so you can run other commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-v sqlvolume:/var/opt/mssql&lt;/strong&gt; is to persist the data &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;mcr.microsoft.com/azure-sql-edge&lt;/strong&gt; is last and it’s the name of the image. This is the same name used in the docker pull command&lt;/p&gt;

</description>
      <category>mssql</category>
      <category>m1</category>
      <category>m2</category>
      <category>docker</category>
    </item>
    <item>
      <title>How to use NVM in Laravel Forge</title>
      <dc:creator>David</dc:creator>
      <pubDate>Fri, 05 Jul 2024 09:18:19 +0000</pubDate>
      <link>https://dev.to/davidgualvez/how-to-use-nvm-in-laravel-forge-32nj</link>
      <guid>https://dev.to/davidgualvez/how-to-use-nvm-in-laravel-forge-32nj</guid>
      <description>&lt;ol&gt;
&lt;li&gt;SSH to forge server and run this command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In forge site deployment script. add this script to install and change the version
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo 'configuring nvm...';
. ~/.nvm/nvm.sh
nvm install v20.0.0
nvm use v20.0.0

echo 'Running &amp;gt; npm install';
npm install

echo 'Running &amp;gt; npm run build';
npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>forge</category>
      <category>nvm</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>How to Validate Array Data in Laravel Using Request Classes</title>
      <dc:creator>David</dc:creator>
      <pubDate>Fri, 05 Jul 2024 09:13:40 +0000</pubDate>
      <link>https://dev.to/davidgualvez/how-to-validate-array-data-in-laravel-using-request-classes-27kp</link>
      <guid>https://dev.to/davidgualvez/how-to-validate-array-data-in-laravel-using-request-classes-27kp</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Create a Request Class:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As before, create a request class with your validation rules.&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:request StoreUserRequest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Define your validation rules in the generated request class (StoreUserRequest):&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\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreUserRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name' =&amp;gt; 'required|string|max:255',
            'email' =&amp;gt; 'required|email|unique:users,email',
            'password' =&amp;gt; 'required|string|min:8',
        ];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Validate the Array Data in the Controller:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In your controller, you can validate the array data using the validation rules from the request class and additional rules if needed.&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\Http\Requests\StoreUserRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class UserController extends Controller
{
    public function store(Request $request)
    {
        // Example array data (in real use-case, this might come from another source)
        $data = [
            'name' =&amp;gt; 'John Doe',
            'email' =&amp;gt; 'john.doe@example.com',
            'password' =&amp;gt; 'secret1234',
            'age' =&amp;gt; 25,
            'terms' =&amp;gt; true,
        ];

        // Retrieve rules from the request class
        $requestClass = new StoreUserRequest();
        $rulesFromRequestClass = $requestClass-&amp;gt;rules();

        // Additional validation rules
        $additionalRules = [
            'age' =&amp;gt; 'required|integer|min:18',
            'terms' =&amp;gt; 'accepted',
        ];

        // Combine rules from the request class and additional rules
        $combinedRules = array_merge($rulesFromRequestClass, $additionalRules);

        // Validate the data array with the combined rules
        $validator = Validator::make($data, $combinedRules);

        if ($validator-&amp;gt;fails()) {
            return response()-&amp;gt;json(['errors' =&amp;gt; $validator-&amp;gt;errors()], 422);
        }

        // Use the validated data for further processing
        $validatedData = $validator-&amp;gt;validated();

        // Example: Create a new user
        $user = User::create($validatedData);

        return response()-&amp;gt;json(['message' =&amp;gt; 'User created successfully', 'user' =&amp;gt; $user], 201);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Customize Validation Messages (Optional):&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can customize the validation messages in the request class as needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function messages()
{
    return [
        'name.required' =&amp;gt; 'The name field is required.',
        'email.required' =&amp;gt; 'The email field is required.',
        'email.email' =&amp;gt; 'The email must be a valid email address.',
        'password.required' =&amp;gt; 'The password field is required.',
        'age.required' =&amp;gt; 'The age field is required.',
        'terms.accepted' =&amp;gt; 'You must accept the terms and conditions.',
    ];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these steps, you can validate array data using the validation rules defined in a request class, combined with additional rules, in your Laravel controller.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>validation</category>
    </item>
    <item>
      <title>A Step-by-Step Guide to Setting Up Supervisord for Laravel in Ubuntu</title>
      <dc:creator>David</dc:creator>
      <pubDate>Thu, 16 Mar 2023 08:19:42 +0000</pubDate>
      <link>https://dev.to/davidgualvez/a-step-by-step-guide-to-setting-up-supervisord-for-laravel-in-ubuntu-441c</link>
      <guid>https://dev.to/davidgualvez/a-step-by-step-guide-to-setting-up-supervisord-for-laravel-in-ubuntu-441c</guid>
      <description>&lt;p&gt;Supervisord is a process management tool that can help you manage processes in your Ubuntu system. It's especially useful if you need to run long-running processes, such as those involved in background tasks, cron jobs, or queue workers. Laravel, a popular PHP framework, relies heavily on background tasks and queue workers to handle tasks such as sending emails, processing uploaded files, and more. In this article, we'll guide you through the process of setting up Supervisord in Ubuntu for Laravel.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install Supervisord
&lt;/h3&gt;

&lt;p&gt;The first step is to install Supervisord on your Ubuntu system. You can do this using the apt package manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; sudo apt-get update
&amp;gt; sudo apt-get install supervisor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install Supervisord and its dependencies on your system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Create a Supervisor Configuration File
&lt;/h3&gt;

&lt;p&gt;Next, you need to create a configuration file for Supervisor. This file will contain information about the processes that you want to manage with Supervisord.&lt;/p&gt;

&lt;p&gt;Create a new configuration file with 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;&amp;gt; sudo nano /etc/supervisor/conf.d/laravel-worker.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open a new file in the Nano text editor. In this file, you can specify the configuration for the Laravel worker process. Here's an example configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/your_project/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/laravel-worker.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration sets up a Laravel worker process that will run the &lt;strong&gt;queue:work&lt;/strong&gt; command with a sleep time of 3 seconds and a maximum of 3 retries. It will run as the &lt;strong&gt;www-data&lt;/strong&gt; user and write its logs to &lt;strong&gt;/var/log/laravel-worker.log&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can adjust these settings to fit your needs. Make sure to replace &lt;strong&gt;/var/www/your_project/artisan&lt;/strong&gt; with the actual path to your Laravel application's &lt;strong&gt;artisan&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;Save and close the file by pressing &lt;strong&gt;Ctrl + X&lt;/strong&gt;, then &lt;strong&gt;Y&lt;/strong&gt;, then &lt;strong&gt;Enter&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Reload Supervisor
&lt;/h3&gt;

&lt;p&gt;Now that you've created your Supervisor configuration file, you need to reload Supervisor to apply the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; sudo supervisorctl reread
&amp;gt; sudo supervisorctl update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will read your new configuration file and update Supervisor's configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Start the Laravel Worker
&lt;/h3&gt;

&lt;p&gt;Finally, you can start the Laravel worker process 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;&amp;gt; sudo supervisorctl start laravel-worker:*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start the Laravel worker process and any child processes that it spawns.&lt;/p&gt;

&lt;p&gt;You can check the status of the Laravel worker process 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;&amp;gt; sudo supervisorctl status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will show you the status of all processes that Supervisor is managing, including your Laravel worker process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we've shown you how to set up Supervisord in Ubuntu for Laravel. By following these steps, you can manage your Laravel worker processes with ease and ensure that they run reliably and consistently. Remember to update your configuration file and reload Supervisor whenever you make changes to your Laravel worker process.&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>laravel</category>
      <category>supervisord</category>
    </item>
    <item>
      <title>How To Secure Nginx with Let's Encrypt on Ubuntu</title>
      <dc:creator>David</dc:creator>
      <pubDate>Thu, 16 Mar 2023 07:05:56 +0000</pubDate>
      <link>https://dev.to/davidgualvez/how-to-secure-nginx-with-lets-encrypt-on-ubuntu-12j1</link>
      <guid>https://dev.to/davidgualvez/how-to-secure-nginx-with-lets-encrypt-on-ubuntu-12j1</guid>
      <description>&lt;p&gt;Certbot is a command-line tool that can be used to obtain and manage SSL/TLS certificates for your website. In order to use Certbot with Nginx on Ubuntu, you can follow these steps:&lt;/p&gt;

&lt;p&gt;Install Certbot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the Nginx plugin for Certbot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install python3-certbot-nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify that your Nginx server blocks are set up correctly 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;sudo nginx -t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the configuration test passes, reload Nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use Certbot to obtain a new SSL/TLS certificate for your domain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot --nginx -d example.com -d www.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;&lt;em&gt;example.com&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;&lt;a href="http://www.example.com" rel="noopener noreferrer"&gt;www.example.com&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; with your actual domain name(s).&lt;/p&gt;

&lt;p&gt;Certbot will guide you through the process of obtaining a new SSL/TLS certificate. You will be prompted to enter your email address and agree to the terms of service. Certbot will then communicate with Let's Encrypt to obtain and install the certificate.&lt;/p&gt;

&lt;p&gt;Once the certificate is installed, Certbot will update your Nginx configuration to use HTTPS. You can verify this 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;sudo nginx -t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the configuration test passes, reload Nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, your Nginx server should now be configured to use HTTPS with a valid SSL/TLS certificate!&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>ssl</category>
      <category>nginx</category>
    </item>
    <item>
      <title>CRONTab Setup for Laravel in Ubuntu</title>
      <dc:creator>David</dc:creator>
      <pubDate>Thu, 16 Mar 2023 06:15:37 +0000</pubDate>
      <link>https://dev.to/davidgualvez/crontab-setup-for-laravel-4pdp</link>
      <guid>https://dev.to/davidgualvez/crontab-setup-for-laravel-4pdp</guid>
      <description>&lt;p&gt;Crontab is a useful tool that can help you automate repetitive tasks in Laravel. With crontab, you can schedule specific commands to run at specified intervals. In this article, we will explore how to set up crontab for Laravel.&lt;/p&gt;

&lt;p&gt;Step 1: Open crontab editor&lt;br&gt;
To begin, open the crontab editor by typing the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; crontab -e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open the crontab editor, allowing you to schedule your commands.&lt;/p&gt;

&lt;p&gt;Step 2: Add Laravel command&lt;br&gt;
Next, add the Laravel command that you want to run. For example, if you want to run the Laravel scheduler every minute, add the following line to your crontab file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* * * * * cd /path/to/laravel-app &amp;amp;&amp;amp; php artisan schedule:run &amp;gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the asterisks represent the schedule interval, which is set to run every minute. You can adjust this to run at different intervals as needed.&lt;/p&gt;

&lt;p&gt;Step 3: Save and exit crontab&lt;br&gt;
Once you have added your Laravel command to the crontab file, save and exit the editor by pressing &lt;strong&gt;'ctrl + X'&lt;/strong&gt; and &lt;strong&gt;'Y + Enter'&lt;/strong&gt;. Your changes will be automatically saved and scheduled to run at the specified intervals.&lt;/p&gt;

&lt;p&gt;Step 4: Verify crontab is running&lt;br&gt;
To verify that your crontab is running, you can check the crontab log file by running 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;&amp;gt; grep CRON /var/log/syslog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will display a log of all the cron jobs that have run on your system, including the Laravel command you just added.&lt;/p&gt;

&lt;p&gt;In conclusion, setting up crontab for Laravel can help you automate repetitive tasks and streamline your development workflow. By following the steps outlined in this article, you can easily schedule Laravel commands to run at specified intervals using crontab.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
