Why we use doctrine package in Laravel

Hello all programmer’s here.

In this blog post I will describe you why we use doctrine library. This libraryis mostly used for modifying the column of database field with change() method to the to column within the migration file.

Let us see how to u…


This content originally appeared on DEV Community and was authored by Snehal

Hello all programmer's here.

In this blog post I will describe you why we use doctrine library. This libraryis mostly used for modifying the column of database field with change() method to the to column within the migration file.

Let us see how to use it

Before modifying the column we first need to install it using the composer.

composer require doctrine/dbal

Let me describe it with an example for better understanding:
You have created a migration file to add is_admin column in users table like below.

Schema::table('users', function (Blueprint $table) {
    $table->unsignedBigInteger('is_admin');
});

But if you want to change the type of the is_admin column from unsignedBigInteger to boolean then you need to add another migration file and add change method to it.

change method allow us to modify type and attribute of an existing column refer to the below code.

Schema::table('users', function (Blueprint $table) {
$table-> boolean(is_admin)->change();
});

This follwing types can be modified: and supported by doctrine library.

bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger, unsignedSmallInteger, and uuid

We can also modify a column to be nullable as shown below:

Schema::table('users', function (Blueprint $table) {
    $table->boolean('is_admin')->nullable()->change();
});

In this way we can modify the type of the field/column within a migration file.

Happy coding. ? ?
Thank you for reading. ?


This content originally appeared on DEV Community and was authored by Snehal


Print Share Comment Cite Upload Translate Updates
APA

Snehal | Sciencx (2021-09-15T17:56:27+00:00) Why we use doctrine package in Laravel. Retrieved from https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/

MLA
" » Why we use doctrine package in Laravel." Snehal | Sciencx - Wednesday September 15, 2021, https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/
HARVARD
Snehal | Sciencx Wednesday September 15, 2021 » Why we use doctrine package in Laravel., viewed ,<https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/>
VANCOUVER
Snehal | Sciencx - » Why we use doctrine package in Laravel. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/
CHICAGO
" » Why we use doctrine package in Laravel." Snehal | Sciencx - Accessed . https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/
IEEE
" » Why we use doctrine package in Laravel." Snehal | Sciencx [Online]. Available: https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/. [Accessed: ]
rf:citation
» Why we use doctrine package in Laravel | Snehal | Sciencx | https://www.scien.cx/2021/09/15/why-we-use-doctrine-package-in-laravel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.