<?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 Tasneem  Wahdan on Medium]]></title>
        <description><![CDATA[Stories by Tasneem  Wahdan on Medium]]></description>
        <link>https://medium.com/@tasneem.90.wahdan?source=rss-37c5a18854ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_eq65YeG1RAqNSkT</url>
            <title>Stories by Tasneem  Wahdan on Medium</title>
            <link>https://medium.com/@tasneem.90.wahdan?source=rss-37c5a18854ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:05:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tasneem.90.wahdan/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[Mastering Self-Relationships in Laravel: One-to-Many and Many-to-Many Explained]]></title>
            <link>https://medium.com/@tasneem.90.wahdan/mastering-self-relationships-in-laravel-one-to-many-and-many-to-many-explained-ec1e3291dd39?source=rss-37c5a18854ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec1e3291dd39</guid>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[self-join]]></category>
            <category><![CDATA[many-to-many]]></category>
            <category><![CDATA[one-to-many]]></category>
            <dc:creator><![CDATA[Tasneem  Wahdan]]></dc:creator>
            <pubDate>Tue, 18 Feb 2025 20:23:58 GMT</pubDate>
            <atom:updated>2025-02-18T20:23:58.124Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*GtrrcYVGLM__pfCgQvfXkA.png" /></figure><h3>Introduction</h3><p>In Laravel, defining relationships between models is usually straightforward when dealing with different entities, such as users and posts. However, what happens when a model needs to relate to itself? This is where <strong>self-relationships</strong> come into play. These relationships are useful for scenarios like <strong>company hierarchies</strong> (managers &amp; employees) or <strong>social networking features</strong> (friendships between users).</p><p>In this guide, we will explore:</p><ul><li><strong>One-to-Many Self-Relationships</strong> (e.g., managers &amp; employees)</li><li><strong>Many-to-Many Self-Relationships</strong> (e.g., user friendships)</li><li>Best practices for handling self-referencing relationships</li></ul><p>By the end of this article, you’ll be able to implement self-relationships efficiently in your Laravel projects!</p><h3>1. Understanding Self-Relationships in Laravel</h3><h3>What is a Self-Relationship?</h3><p>A self-relationship is a relationship where a model is related to itself. In other words, records in the same database table reference other records within the same table.</p><h3>When Do We Need It?</h3><p>Self-relationships are useful when a model needs to have hierarchical or bidirectional connections with other records of the same type. Examples include:</p><ul><li><strong>Employee-Manager Hierarchy</strong> (An employee reports to a manager, but both are users)</li><li><strong>Friendship System</strong> (Users can add other users as friends)</li><li><strong>Category Subcategories</strong> (Categories can have subcategories that belong to the same table)</li></ul><h3>2. One-to-Many Self-Relationship (Manager &amp; Employees)</h3><h3>Step 1: Creating the Migration</h3><p>Run the following command to create the employees table:</p><pre>php artisan make:migration create_employees_table</pre><p>Modify the generated migration file:</p><pre>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;</pre><pre>return new class extends Migration {<br>    public function up()<br>    {<br>        Schema::create(&#39;employees&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;foreignId(&#39;manager_id&#39;)-&gt;nullable()-&gt;constrained(&#39;employees&#39;)-&gt;onDelete(&#39;cascade&#39;);<br>            $table-&gt;timestamps();<br>        });<br>    }</pre><pre>    public function down()<br>    {<br>        Schema::dropIfExists(&#39;employees&#39;);<br>    }<br>};</pre><p>Run the migration:</p><pre>php artisan migrate</pre><h3>Step 2: Defining the Relationships in the Employee Model</h3><p>Modify Employee.php:</p><pre>use Illuminate\Database\Eloquent\Model;</pre><pre>class Employee extends Model<br>{<br>    public function manager()<br>    {<br>        return $this-&gt;belongsTo(Employee::class, &#39;manager_id&#39;);<br>    }</pre><pre>    public function subordinates()<br>    {<br>        return $this-&gt;hasMany(Employee::class, &#39;manager_id&#39;);<br>    }<br>}</pre><h3>Step 3: Using the Relationships in Code</h3><h4>Assigning a Manager to an Employee</h4><pre>$manager = Employee::create([&#39;name&#39; =&gt; &#39;John Doe&#39;]);<br>$employee = Employee::create([&#39;name&#39; =&gt; &#39;Jane Smith&#39;, &#39;manager_id&#39; =&gt; $manager-&gt;id]);</pre><h4>Retrieving Employees Under a Manager</h4><pre>$manager = Employee::find(1);<br>$subordinates = $manager-&gt;subordinates;</pre><h4>Retrieving an Employee’s Manager</h4><pre>$employee = Employee::find(2);<br>echo &quot;Manager: &quot; . $employee-&gt;manager-&gt;name;</pre><h3>3. Many-to-Many Self-Relationship (User Friendships)</h3><h3>Step 1: Creating a Pivot Table</h3><p>Run the following command:</p><pre>php artisan make:migration create_friend_user_table</pre><p>Modify the migration file:</p><pre>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;</pre><pre>return new class extends Migration {<br>    public function up()<br>    {<br>        Schema::create(&#39;friend_user&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;foreignId(&#39;user_id&#39;)-&gt;constrained(&#39;users&#39;)-&gt;onDelete(&#39;cascade&#39;);<br>            $table-&gt;foreignId(&#39;friend_id&#39;)-&gt;constrained(&#39;users&#39;)-&gt;onDelete(&#39;cascade&#39;);<br>            $table-&gt;timestamps();<br>            $table-&gt;unique([&#39;user_id&#39;, &#39;friend_id&#39;]);<br>        });<br>    }</pre><pre>    public function down()<br>    {<br>        Schema::dropIfExists(&#39;friend_user&#39;);<br>    }<br>};</pre><p>Run the migration:</p><pre>php artisan migrate</pre><h3>Step 2: Defining the Relationship in the User Model</h3><p>Modify User.php:</p><pre>use Illuminate\Database\Eloquent\Model;</pre><pre>class User extends Model<br>{<br>    public function friends()<br>    {<br>        return $this-&gt;belongsToMany(User::class, &#39;friend_user&#39;, &#39;user_id&#39;, &#39;friend_id&#39;);<br>    }</pre><pre>    public function addFriend(User $friend)<br>    {<br>        $this-&gt;friends()-&gt;syncWithoutDetaching([$friend-&gt;id]);<br>        $friend-&gt;friends()-&gt;syncWithoutDetaching([$this-&gt;id]);<br>    }<br>}</pre><h3>Step 3: Using the Relationship</h3><h4>Adding Friends</h4><pre>$user1 = User::create([&#39;name&#39; =&gt; &#39;Alice&#39;]);<br>$user2 = User::create([&#39;name&#39; =&gt; &#39;Bob&#39;]);<br>$user1-&gt;addFriend($user2);</pre><h4>Retrieving Friends</h4><pre>$alice = User::find(1);<br>echo &quot;Alice&#39;s friends: &quot; . implode(&#39;, &#39;, $alice-&gt;friends-&gt;pluck(&#39;name&#39;)-&gt;toArray());</pre><h3>4. Best Practices for Self-Relationships</h3><ul><li><strong>Ensure data integrity</strong> using unique constraints on pivot tables.</li><li><strong>Use </strong><strong>syncWithoutDetaching()</strong> instead of attach() to prevent duplicate entries.</li><li><strong>Use bidirectional updates</strong> in many-to-many relationships for mutual connections.</li><li><strong>Avoid infinite loops</strong> when retrieving hierarchical relationships.</li></ul><h3>5. Conclusion &amp; Next Steps</h3><p>Self-relationships in Laravel are powerful tools for managing hierarchical and mutual connections. Whether you’re building an <strong>employee management system</strong> or a <strong>social networking feature</strong>, understanding one-to-many and many-to-many self-relationships is crucial.</p><p>You can further enhance this by implementing <strong>friend requests</strong>, <strong>blocking users</strong>, or <strong>recursive relationships</strong> (e.g., unlimited category nesting).</p><p>Now, go ahead and experiment with self-relationships in your Laravel projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec1e3291dd39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Website’s Settings Made Simple: How to Save and Handle Them Efficiently]]></title>
            <link>https://medium.com/@tasneem.90.wahdan/laravel-settings-made-simple-how-to-save-and-handle-them-efficiently-dd082e192b01?source=rss-37c5a18854ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd082e192b01</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel-configuration]]></category>
            <category><![CDATA[settings]]></category>
            <dc:creator><![CDATA[Tasneem  Wahdan]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 18:41:40 GMT</pubDate>
            <atom:updated>2024-11-24T18:52:57.845Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*iNIVjVsnEFyE4cc1IevjpA.png" /></figure><p>In the dynamic world of web development, flexibility and maintainability are crucial for building robust applications. Laravel, known for its elegant syntax and powerful tools, offers multiple ways to manage application settings. From handling configurations through JSON files to leveraging database-driven approaches, Laravel provides developers with the tools to balance simplicity and scalability.</p><p>But as your project grows, so does the complexity of managing these settings effectively. How do you ensure that your settings are secure, easily editable, and performant for administrators?</p><p>This article will explore a practical guide to saving and managing settings in a Laravel project. Whether you’re dealing with global application settings like website titles and descriptions, or specific configurations for loyalty points, we’ll cover step-by-step approaches to make your project scalable and admin-friendly. By the end, you’ll clearly understand how to implement and optimize your settings for both development and production environments.</p><p>Let’s dive in!</p><p><strong>Step 1: Store Settings in the Database</strong>:</p><p>Create a migration file that will be used to save settings in the database as a key-value store:</p><pre>php artisan make:migration create_settings_table</pre><p>in the generated migration file, add key and value columns like this:</p><pre>Schema::create(&#39;settings&#39;, function (Blueprint $table) {<br>    $table-&gt;string(&#39;key&#39;)-&gt;unique();<br>    $table-&gt;text(&#39;value&#39;);<br>    $table-&gt;timestamps();<br>});</pre><p><strong>Step 2: Create Setting Model</strong>:</p><p>Run the command:</p><pre>php artisan make:model Setting</pre><p>Open the generated Setting model file, and add $fillable fields:</p><pre>namespace App\Models;<br><br>use Illuminate\Database\Eloquent\Model;<br><br>class Setting extends Model<br>{<br>    protected $fillable = [&#39;key&#39;, &#39;value&#39;];<br>}</pre><p><strong>Step 3: Add Initial Settings By Seeder:</strong></p><p>To create a seeder class for settings run this command:</p><pre>php artisan make:seeder SettingsSeeder</pre><p>In the SettingsSeeder class, add the settings key-value pairs according to your project needs:</p><pre>use App\Models\Setting;<br><br>public function run()<br>{<br>    Setting::insert([<br>        [&#39;key&#39; =&gt; &#39;site_title&#39;, &#39;value&#39; =&gt; &#39;My Awesome Website&#39;],<br>        [&#39;key&#39; =&gt; &#39;site_description&#39;, &#39;value&#39; =&gt; &#39;Default website description.&#39;],<br>        [&#39;key&#39; =&gt; &#39;website_logo&#39;, &#39;value&#39; =&gt; &#39;/images/logo.png&#39;], <br>        [&#39;key&#39; =&gt; &#39;points_expiry_days&#39;, &#39;value&#39; =&gt; &#39;365&#39;],<br>        // Add other settings as needed<br>    ]);<br>}</pre><p>Then, run the seeder:</p><pre>php artisan db:seed --class=SettingsSeeder</pre><p><strong>Step 4: Retrieve Settings from the Database to Access Settings in Your Application:</strong></p><p>the database and override the values defined in the config file. You can do this using a service provider:</p><p>In your <strong>AppServiceProvider</strong>(or a custom service provider), add the following in the <strong>boot()</strong> method:</p><pre>use App\Models\Setting;<br><br>public function boot()<br>    {<br>        if (Schema::hasTable(&#39;settings&#39;)) {<br>            $settings = Setting::all()-&gt;pluck(&#39;value&#39;, &#39;key&#39;)-&gt;toArray();<br>            config([&#39;settings&#39; =&gt; $settings]);  // Load the settings dynamically into Laravel&#39;s config<br>        }<br><br>    }</pre><p>This makes all settings accessible via <strong>config(‘settings.key’)</strong>, for example <strong>config(‘settings.site_title’)</strong>.</p><p>Congrats! Now, you can create an edit form for admin, for example, that displays the initial seeded settings, where he can update them as needed.</p><p>You will need to create the needed controller, routes to handle edit and update methods, and blade view to show the edit form.</p><p>This is an example of an edit form in the blade view file:</p><pre>&lt;form action=&quot;{{ route(&#39;admin.settings.update&#39;) }}&quot; method=&quot;POST&quot;&gt;<br>    @csrf<br>    &lt;div&gt;<br>        &lt;label for=&quot;site_title&quot;&gt;Site Title&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;site_title&quot; value=&quot;{{ config(&#39;settings.site_title&#39;) }}&quot; /&gt;<br>    &lt;/div&gt;<br>    <br>    &lt;div&gt;<br>        &lt;label for=&quot;site_description&quot;&gt;Site Description&lt;/label&gt;<br>        &lt;textarea name=&quot;site_description&quot; class=&quot;form-control&quot;&gt;{{config(&#39;settings.site_description&#39;)}}&lt;/textarea&gt;<br>    &lt;/div&gt;<br><br>    &lt;div&gt;<br>        &lt;label&gt;Current Logo&lt;/label&gt;<br>           &lt;img src=&quot;{{Storage::url(https://medium.com/config(&#39;settings.website_logo&#39;))}}&quot; style=&quot;max-width:190px;&quot;&gt;<br>    &lt;/div&gt;<br><br>    &lt;div&gt;<br>        &lt;label for=&quot;website_logo&quot;&gt;Upload New Logo&lt;/label&gt;<br>        &lt;input name=&quot;website_logo&quot; type=&quot;file&quot; id=&quot;website_logo&quot; class=&quot;form-control&quot;&gt;<br>    &lt;/div&gt;<br>    &lt;button type=&quot;submit&quot;&gt;Save Settings&lt;/button&gt;<br>&lt;/form&gt;</pre><p><strong>Conclusion</strong></p><p>By implementing a robust system for handling settings, you not only simplify development but also empower your application to grow alongside your needs. As you continue refining your Laravel project, remember that well-managed settings are the foundation for a streamlined and adaptable application. Take the time to plan and execute this aspect carefully — it will pay dividends in the long run.</p><p>With the tools and techniques covered in this guide, you’re well-equipped to make your Laravel settings management both efficient and future-proof.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd082e192b01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Access MySql Database on Digitalocean’s Droplet From Localhost Using PhpMyAdmin]]></title>
            <link>https://medium.com/@tasneem.90.wahdan/access-mysql-database-on-digitaloceans-droplet-from-localhost-using-phpmyadmin-42ec01129cfe?source=rss-37c5a18854ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/42ec01129cfe</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[phpmyadmin]]></category>
            <category><![CDATA[digitalocean]]></category>
            <dc:creator><![CDATA[Tasneem  Wahdan]]></dc:creator>
            <pubDate>Sun, 13 Oct 2024 09:07:17 GMT</pubDate>
            <atom:updated>2024-10-13T09:07:17.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*J0odhzb3ZOPQmhT5_epE2g.png" /></figure><p>After switching from using shared hosting with cPanel to DigitalOcean’s droplet, I found it harder to access databases to export, import, modify…etc, which was simple on cPanel.</p><p>I decided to write this article as a reference and to help others access the database from localhost using PhpMyAdmin.</p><h3>Step 1: Enable Remote Access to MySQL on the Droplet</h3><p>By default, MySQL is usually configured to accept connections only from localhost for security reasons. You need to configure MySQL to accept remote connections.</p><ol><li><strong>SSH into your Droplet</strong>:</li></ol><pre>ssh root@your_droplet_ip</pre><p>2. <strong>Edit the MySQL configuration file</strong> (my.cnf or mysqld.cnf):</p><p>The file is typically located at /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/mysql/my.cnf, depending on your setup. Open the file for editing:</p><pre>sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf</pre><p><strong>3. Change the bind-address</strong>:</p><p>Find the line that reads bind-address = 127.0.0.1 and change it to 0.0.0.0 to allow connections from any IP:</p><pre>bind-address = 0.0.0.0</pre><p>4. <strong>Save the file</strong> and exit the editor (CTRL+X, then Y, then Enter).</p><p>5. <strong>Restart MySQL</strong> to apply the changes:</p><pre>sudo service mysql restart</pre><h3>Step 2: Allow Firewall Access (if applicable)</h3><p>If your droplet has a firewall (like UFW), you’ll need to open port 3306 (the default MySQL port) for remote access.</p><p>To allow connections from a specific IP (for security):</p><pre>sudo ufw allow from your_local_ip to any port 3306</pre><p>Or, to allow access from any IP (less secure):</p><pre>sudo ufw allow 3306</pre><h3>Step 3: Create or Configure a MySQL User for Remote Access</h3><p>Ensure the MySQL user you’re using allows connections from remote IPs, not just localhost.</p><ol><li><strong>Log into MySQL</strong>:</li></ol><pre>sudo mysql -u root -p</pre><p><strong>2. Create a new user with remote access</strong> or modify an existing user:</p><p>To create a new user that can connect from any IP:</p><pre>CREATE USER &#39;your_username&#39;@&#39;%&#39; IDENTIFIED BY &#39;your_password&#39;;<br>GRANT ALL PRIVILEGES ON your_db_name.* TO &#39;your_username&#39;@&#39;%&#39;;<br>FLUSH PRIVILEGES;</pre><p>If you want the user to connect only from a specific IP (like your local machine):</p><pre>CREATE USER &#39;your_username&#39;@&#39;your_local_ip&#39; IDENTIFIED BY &#39;your_password&#39;;<br>GRANT ALL PRIVILEGES ON your_db_name.* TO &#39;your_username&#39;@&#39;your_local_ip&#39;;<br>FLUSH PRIVILEGES;</pre><h3>Step 4: Install phpMyAdmin on Your Local Computer</h3><ol><li><strong>Install phpMyAdmin</strong>:</li></ol><ul><li>If you’re using <strong>XAMPP</strong>, phpMyAdmin is included.</li><li>Alternatively, you can install phpMyAdmin locally following the instructions for your operating system.</li></ul><p><strong>2. Configure phpMyAdmin</strong> to access the droplet’s MySQL:</p><ul><li>Open phpMyAdmin.</li><li>On the login screen, enter:</li><li><strong>Server</strong>: your_droplet_ip</li><li><strong>Username</strong>: your_mysql_username</li><li><strong>Password</strong>: your_mysql_password</li><li><strong>Database</strong>: (optional, leave empty to access all databases)</li></ul><h3>Step 5: Log in to phpMyAdmin</h3><p>Once everything is set up, you should be able to log in to phpMyAdmin using your droplet’s MySQL credentials and access your database.</p><p><strong>Note:</strong> If you already have PhpMyAdmin installed and you use it already, you can simply add new server to login to like this:</p><h4>Step 1: Locate the phpMyAdmin Configuration File</h4><p>The main configuration file for phpMyAdmin is config.inc.php. It is typically located in the directory where phpMyAdmin is installed.</p><p>If you’re using <strong>XAMPP</strong> or <strong>MAMP</strong>, this file might be in:</p><ul><li><strong>XAMPP</strong>: C:\xampp\phpMyAdmin\config.inc.php</li><li><strong>MAMP</strong>: /Applications/MAMP/bin/phpMyAdmin/config.inc.php</li></ul><p>For standalone phpMyAdmin installations, it could be in /etc/phpmyadmin/ or a similar location on your system.</p><h4>Step 2: Edit the config.inc.php File</h4><p>Open the config.inc.php file in a text editor with administrator/root permissions.</p><h4>Step 3: Add a New Server Configuration</h4><p>Find the section that defines the servers. It usually looks like this:</p><pre>/* Servers configuration */<br>$i = 0;<br>$i++;<br>/* First server */<br>$cfg[&#39;Servers&#39;][$i][&#39;host&#39;] = &#39;localhost&#39;;<br>$cfg[&#39;Servers&#39;][$i][&#39;user&#39;] = &#39;root&#39;;<br>$cfg[&#39;Servers&#39;][$i][&#39;password&#39;] = &#39;&#39;;<br>$cfg[&#39;Servers&#39;][$i][&#39;auth_type&#39;] = &#39;cookie&#39;;</pre><p>To add your DigitalOcean droplet as a new server, add the following block right below it:</p><pre>$i++;<br>/* Second server (DigitalOcean Droplet) */<br>$cfg[&#39;Servers&#39;][$i][&#39;host&#39;] = &#39;your_droplet_ip&#39;;  // Replace with your droplet IP<br>$cfg[&#39;Servers&#39;][$i][&#39;user&#39;] = &#39;your_mysql_username&#39;;  // Replace with your MySQL username<br>$cfg[&#39;Servers&#39;][$i][&#39;password&#39;] = &#39;your_mysql_password&#39;;  // Replace with your MySQL password<br>$cfg[&#39;Servers&#39;][$i][&#39;auth_type&#39;] = &#39;cookie&#39;;<br>$cfg[&#39;Servers&#39;][$i][&#39;port&#39;] = &#39;3306&#39;;  // Optional, if MySQL is using the default port</pre><h4>Step 4: Save and Reload phpMyAdmin</h4><p>After saving the file, reload phpMyAdmin in your browser. You should now see an option to select the new server (your DigitalOcean droplet) from the dropdown when logging in.</p><h4>Step 5: Log in to the New Server</h4><ul><li>Select the new server from the dropdown menu.</li><li>Enter the MySQL username and password you created for remote access.</li></ul><p>This should allow you to manage both your local databases and the remote database on your DigitalOcean droplet through phpMyAdmin.</p><h4>Important Security Note:</h4><p>Allowing remote access to MySQL can be a security risk, so it’s recommended to:</p><ul><li>Only allow specific IPs to connect.</li><li>Use strong passwords.</li><li>Use a firewall to limit access to port 3306.</li><li>Consider using SSH tunneling instead of exposing MySQL directly over the internet.</li></ul><p>I hope that you found this article helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42ec01129cfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect DigitalOcean’s Droplet with GitHub Repository Using SSH KEY]]></title>
            <link>https://medium.com/@tasneem.90.wahdan/connect-digitaloceans-droplet-with-github-repository-using-ssh-key-6354308cdfef?source=rss-37c5a18854ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/6354308cdfef</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[digital-ocean-droplet]]></category>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Tasneem  Wahdan]]></dc:creator>
            <pubDate>Tue, 10 Sep 2024 17:56:38 GMT</pubDate>
            <atom:updated>2024-09-10T18:00:28.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*BXG7IypgjDSETkkvDEE8Eg.png" /><figcaption>How To Setup SSH Keys</figcaption></figure><p>I have a website that is hosted on DigitalOcean’s droplet, and I needed to connect it with my GitHub repository to pull changes from there on the server.</p><p><strong><em>Note before you start:</em></strong><em> From DigitalOcean’s dashboard, you can go to your droplet and click on the ‘console’ button to open your droplet’s terminal.</em></p><p>Here’s how to set it up:</p><h3>1. Generate an SSH Key on Your Droplet</h3><p>First, check if you already have an SSH key by running:</p><pre>ls ~/.ssh/id_rsa.pub</pre><p>If you see the file, you already have an SSH key. If not, generate a new one:</p><pre>ssh-keygen -t rsa -b 4096 -C &quot;your_email@example.com&quot;</pre><ul><li><strong>Press Enter</strong> to accept the default file location.</li><li>When asked for a passphrase, you can press Enter to leave it empty (unless you want additional security).</li></ul><p>This will generate two files:</p><ul><li>~/.ssh/id_rsa (your private key)</li><li>~/.ssh/id_rsa.pub (your public key)</li></ul><h3>2. Add Your SSH Key to the SSH Agent</h3><p>To ensure the SSH key is used, add it to the SSH agent:</p><pre>eval &quot;$(ssh-agent -s)&quot;<br>ssh-add ~/.ssh/id_rsa</pre><h3>3. Add the SSH Key to Your GitHub Account</h3><ol><li><strong>Copy the SSH public key</strong> to your clipboard</li></ol><pre>cat ~/.ssh/id_rsa.pub</pre><p>Copy the entire output (your public key).</p><p>2.<strong> Add the SSH key to GitHub</strong>:</p><ul><li>Go to your <strong>GitHub account</strong>.</li><li>Navigate to <strong>Settings</strong> &gt; <strong>SSH and GPG keys</strong>.</li><li>Click on <strong>New SSH Key</strong>.</li><li>Paste the public key and give it a recognizable title (e.g., “Staging Droplet”).</li></ul><h3>4. Update Your Git Remote to Use SSH</h3><p>Your current Git setup is probably using the HTTPS URL, which requires username/password or token-based authentication. You need to switch to SSH-based authentication.</p><ol><li><strong>Check your current remote URL</strong>:</li></ol><pre>git remote -v</pre><p>2.<strong> Change the remote URL to use SSH</strong>: Replace the existing HTTPS remote with SSH:</p><pre>git remote set-url origin git@github.com:your-username/your-repo.git</pre><p>Make sure to replace your-username and your-repo with your actual GitHub username and repository name.</p><h3>5. Test the SSH Connection</h3><p>To verify that the SSH connection works properly, run:</p><pre>ssh -T git@github.com</pre><p>You should see a message like:</p><pre>Hi your-username! You&#39;ve successfully authenticated, but GitHub does not provide shell access.</pre><p>Congrats! Now, you are ready to pull changes from GitHub’s Repository using SSH.</p><p>Next article, I will explain how to automatically pull changes from the GitHub repository’s main branch into the droplet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6354308cdfef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trie Implementation in PHP]]></title>
            <link>https://medium.com/@tasneem.90.wahdan/trie-implementation-in-php-2b1f0251b739?source=rss-37c5a18854ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b1f0251b739</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[trie]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Tasneem  Wahdan]]></dc:creator>
            <pubDate>Tue, 14 Mar 2023 09:22:43 GMT</pubDate>
            <atom:updated>2023-03-14T09:22:43.544Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Trie</strong> is a tree data structure used for storing and locating keys from a set. The keys are usually strings that are stored character by character — each node of a trie corresponds to a single character rather than the entire key.</p><p>The order of characters in a string is represented by edges between the adjacent nodes. For example, the string “are” will have an edge from node <em>a</em> to node <em>r</em> to node <em>e</em>. That is, node <em>a</em> will be the parent of node <em>r</em>, and node <em>r</em> will be the parent of node <em>e</em>.</p><p>The following is the Trie implementation in PHP, which includes inserting a new word into the Trie, searching for a word, and checking if a word prefix exists.</p><pre>class TrieNode{<br>    public $children = [];<br>    public $isEnd = false;<br>}<br><br>class Trie {<br>    /**<br>     */<br>    public $node; <br>    function __construct() {<br>        $this-&gt;node = new TrieNode();        <br>    }<br>  <br>    /**<br>     * @param String $word<br>     * @return NULL<br>     */<br><br>     public function insert($word) <br>    {<br>        $count = strlen($word);<br>        $node = $this-&gt;node;<br>        for ($i = 0; $i &lt; $count; $i++) {<br>            $char = $word[$i];<br>            if (isset($node-&gt;children[$char])) {<br>                $node = $node-&gt;children[$char];<br>                continue;<br>            }<br>            $node-&gt;children[$char] = new TrieNode();<br>            $node = $node-&gt;children[$char];<br>        }<br>        $node-&gt;isEnd = true;<br>    }<br>  <br>    /**<br>     * @param String $word<br>     * @return Boolean<br>     */<br>    function search($word) {<br>        $node = $this-&gt;node;<br>        for($i =0; $i &lt; strlen($word); $i++){<br>            $char = $word[$i];<br>            if(! isset($node-&gt;children[$char]))<br>                return false;<br>            $node = $node-&gt;children[$char];    <br>        }<br>        return $node-&gt;isEnd;<br>        <br>    }<br>  <br>    /**<br>     * @param String $prefix<br>     * @return Boolean<br>     */<br>    function startsWith($prefix) {<br>        $node = $this-&gt;node;<br>        for($i = 0; $i &lt; strlen($prefix); $i++){<br>            $char = $prefix[$i];<br>            if(! isset($node-&gt;children[$char]))<br>                return false;<br>            $node = $node-&gt;children[$char];    <br>        }<br>        return true;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b1f0251b739" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>