<?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>Forem: Mahmoud Abd Elhalim</title>
    <description>The latest articles on Forem by Mahmoud Abd Elhalim (@mahmoud_abd_elhalim).</description>
    <link>https://forem.com/mahmoud_abd_elhalim</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%2F837569%2F6ec27874-c362-44de-8c35-0480d5331fff.jpg</url>
      <title>Forem: Mahmoud Abd Elhalim</title>
      <link>https://forem.com/mahmoud_abd_elhalim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mahmoud_abd_elhalim"/>
    <language>en</language>
    <item>
      <title>How To Add A New Column Using Laravel Migration?</title>
      <dc:creator>Mahmoud Abd Elhalim</dc:creator>
      <pubDate>Sat, 18 Mar 2023 15:57:49 +0000</pubDate>
      <link>https://forem.com/mahmoud_abd_elhalim/how-to-add-a-new-column-using-laravel-migration-93d</link>
      <guid>https://forem.com/mahmoud_abd_elhalim/how-to-add-a-new-column-using-laravel-migration-93d</guid>
      <description>&lt;p&gt;In this post, we will focus on the Add new column after another column in our DB table. step by step explain how to add a new column in the migration file.  follow the below step to learn how to do it.&lt;/p&gt;

&lt;p&gt;will give you a simple example of how to add a column after a specific column in Laravel migration. Alright, let’s dive into the details.  for example, we have the "posts" table with columns: &lt;/p&gt;

&lt;p&gt;['id', 'title', 'body', 'created_at', 'updated_at'] and we need to add the "status" column after the body column into the table.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Firstly Create a Migration File&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then use the after() method from Schema to do it with syntax $table-&amp;gt;boolean('status')-&amp;gt;after('body');&lt;br&gt;
&lt;/p&gt;

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table-&amp;gt;boolean('status')-&amp;gt;after('body');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {

        });
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can run the migration command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;You can See &lt;a href="https://mahmoudabdelhalim.com/post/the-7-most-important-software-design-patterns"&gt;The Most Important Software Design Patterns&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Change Table Name Using Laravel Migration</title>
      <dc:creator>Mahmoud Abd Elhalim</dc:creator>
      <pubDate>Sat, 18 Mar 2023 15:29:07 +0000</pubDate>
      <link>https://forem.com/mahmoud_abd_elhalim/change-table-name-using-laravel-migration-ofj</link>
      <guid>https://forem.com/mahmoud_abd_elhalim/change-table-name-using-laravel-migration-ofj</guid>
      <description>&lt;p&gt;Hello bro,&lt;/p&gt;

&lt;p&gt;In this post we will focus on the main operations we need to do on any Laravel project, for example, will learn you how to change column type in the migration file. step by step explain how to rename column names in the migration file. another one is how to rename the table names using the migration file,  follow the below step to learn how to do it.&lt;br&gt;
I will give you two examples of main operations can we use in all Laravel versions from 5 to above.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;First of all we need to install "doctrine/dbal" composer package.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;composer require doctrine/dbal&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After successfully installing the composer package we can proceed to explain the operations.&lt;/p&gt;

&lt;p&gt;we can easily rename table name's using Schema rename method. so let's do this, for example, we have a table called "articles" and we need to change the name to a new one called "posts"&lt;/p&gt;

&lt;p&gt;Create Migration File&lt;br&gt;
&lt;code&gt;php artisan make:migration RenameArticlesTable&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then use the rename method from Schema to do it with syntax &lt;strong&gt;Schema::rename('old_table_name', 'new_table_name');&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::rename('posts', 'articles');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
};

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

&lt;/div&gt;



&lt;p&gt;Now, you can run the migration command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For &lt;a href="https://mahmoudabdelhalim.com/post/how-to-add-a-new-column-using-laravel-migration"&gt;How To Add A New Column Using Laravel Migration?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

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