Altering a database view by Laravel migration

If you are working in Laravel and you create database migration script each time you modified database structure, then you may need to alter an already created database view.

Most of developers do not work with views but sometimes creating views is a good option like when you are using same complex query  with multiple joins in multiple places throughout the application.

For example –

There is a view as :

Now if you want to add 1 more column, then you have to create migration script in Laravel.

To create migration script in Laravel, you can run this command in terminal (from the root directory of laravel.

After running this command a migration file will be created in base_dir/database/migrations/2018_04_28_155833_alter_project_view.php


Now you need to add alter query in up() function. There is no way to add only 1 column without writing whole query like for table.

In this example I added 1 more column CreatedDate.

Here you don’t need to write anything in down() function.

Now you need to run this migration script just by command


check out our blog to create custom form validator in Laravel

Please follow and like us: