14 ш - перевести

laravel web developers new york https://webstart.am/en/laravel..../laravel-development Laravel migrations are a powerful tool for managing the database structure. They allow you to create versions of the database schemes, make changes and update the structure without the need to write pure SQL, which is especially useful when working in a team and when deploying a project into different environment.

The main steps when using migrations in Laravel:

1. Creating migration:
To create new migration, use the Artisan command:

Php Artisan Make: Migration Create_users_table


This team generates the migration file in the catalog `Database/Migrations`. The name of the file usually contains a temporary mark and description.

2. Definition of the structure of the table:
In the migration file you will find two methods: `up ()` and `download ()`. In the `up () method, determine the structure of the table that will be created when performing migration, and in` download () ` - the logic of removal or rollback of changes.
Example:

Public Function Up ()
{
Schema :: Create ('Users', Function (Blueprint $ Table) {
$ table-> id ();
$ Table-> String ('Name';
$ Table-> String ('Email'-> Unique ();
$ Table-> TimeStamp ('Email_verified_at'-> Nullable ();
$ Table-> String ('Password';
$ Table-> RememberToken ();
$ Table-> Timestamps ();
});
}

Public Function Down ()
{
Schema :: dropifexists ('users';
}



3. Migration:
Launch of all not made migrations:

PHP Artisan Migrate


This will create or update the tables in the database based on definitions in migrations.

4. Migration rollback:
To return to the previous state, use the command:

PHP Artisan Migrate: Rollback


It cancels the latest migrations.

5. Migration Management:
Laravel allows you to create migrations to add, change or delete columns and tables, making work very flexible. You can also use commands to create migrations with templates:

• `Php Artisan Make: Migration Add_avatar_to_users_table --table = users` -to add new columns.
• `PHP Artisan Migrate: Fresh` - to dump all the tables and re -fulfill all migrations (use with caution).

It is important to observe the correct sequence of migration, especially with changes in the structure of tables in order to avoid errors and data loss.

Laravel Development Agency in New York – Webstart
webstart.am

Laravel Development Agency in New York – Webstart

Hire a professional Laravel development agency in New York. Webstart builds secure, scalable, and high-performance Laravel web applications. Free consultation!