Laravel Creating Tables

Create Table Migration

Use this command to generate a migration for creating a table:

php artisan make:migration create_posts_table


This generates a file in database/migrations/:

public function up(): void
{
  Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('content');
    $table->timestamps();
  });
}

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


Running Migrations:

Run all pending migrations and create tables

php artisan migrate
Output:
Name Type
id bigint(20)
title varchar(255)
content text
created_at timestamp
updated_at timestamp

Rollback Comment:

Rollback the last batch of migrations so table is removed from database

php artisan migrate:rollback

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.