How does Laravel's migration up and down method work?

Related searches

In this code the table is created in the up method and deleted in the down() method. When I run the migration, the table is created but not deleted. In what way can I trigger the down method, so that I get a better understanding on how the two methods work?

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFlightsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('flights', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('airline');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('flights');
    }
}
In your example:

php artisan migrate will run your up() method.

php artisan migrate:rollback will run your down() method.

Read up on the excellent docs: https://laravel.com/docs/5.7/migrations#migration-structure

Request Lifecycle - Laravel, The goal of this document is to give you a good, high-level overview of how the Laravel framework "works". By getting to know the overall framework better,� The next thing you should do after installing Laravel is set your application key to a random string. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command. Typically, this string should be 32 characters long. The key can be set in the .env environment file.

Try:

public function down()
{
    Schema::dropIfExists('flights');
}

How Laravel implements MVC and how to use it effectively, The goal of this document is to give you a good, high-level overview of how the Laravel framework works. By getting to know the overall framework better,� How Does Laravel pluck() Work? The Laravel pluck as the name suggests, extracts certain values, as suggested. It literally plucks the information out from the given array and produces it as an output. However, it is most effective against objectives, but will work well against arrays too. Example #1. The first one is by using one parameter.

You sohuld add dropIfExists instead of drop

and if you wanna just drop the specific migration file you should write your code in command like this:

php artisan migrate:rollback --path=\database\migrations\flights.php

What is Laravel? Laravel is a PHP-based web framework that is largely based on the MVC architecture. Laravel was created to make it easier� That is Laravel telling you, you can put something here, or not, the software will continue working either way.

Laravel is simpler to use. It also gives options to developers for similar functions. For example, DISTINCT can always It integrates with the mail services. The integration with the tool makes building web applications faster and smoother. Automation testing is one of the quickest in Laravel.

Laravel also provides a mechanism for invalidating and "logging out" a user's sessions that are active on other devices without invalidating the session on their current device. This feature is typically utilized when a user is changing or updating their password and you would like to invalidate sessions on other devices while keeping the current device authenticated.

In this guide we have looked at what Vue.js can do and how it can work with Laravel. We explored some reasons why you should consider using Vue with Laravel. We also looked at how to use Vue with Laravel, including making a single page application that will run on Laravel. There is a whole lot you can build with Vue and Laravel.

Comments
  • laravel.com/docs/5.6/migrations#rolling-back-migrations
  • You have any error in your first trying migration ?
  • I copied the code from the documentation. I ran the code the table is getting created.
  • The down method exists to run when the migration is rolled back, e.g: php artisan migrate:rollback will delete the table flights. You are expected to write code to reverse what was done in up, e.g: if up adds a new column; down deletes it. The down method only runs when you roll back the migration.
  • Also there is create method to create a new table but there is the table method to update existing tables. How to use those? I mean create method will go in one class and when I want to edit the existing table should I create a new class and use the table method?