Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 15, 2021 05:56 pm GMT

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 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.


Original Link: https://dev.to/snehalk/why-we-use-doctrine-package-in-laravel-26jm

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To