master

laravel/framework

Last updated at: 29/12/2023 09:24

Schema.php

TLDR

The Schema.php file in the Illuminate\Support\Facades namespace contains the Schema class, which is a facade for interacting with database schemas. It provides various methods for performing actions such as creating or dropping tables, modifying columns, and retrieving information about tables, columns, indexes, and foreign keys.

Methods

defaultStringLength

Sets the default string length for string columns.

defaultMorphKeyType

Sets the default key type for morph relationships.

morphUsingUuids

Sets the key type for morph relationships to UUIDs.

morphUsingUlids

Sets the key type for morph relationships to ULIDs.

useNativeSchemaOperationsIfPossible

Specifies whether to use native database schema operations, if available.

createDatabase

Creates a new database with the given name.

dropDatabaseIfExists

Drops an existing database with the given name, if it exists.

hasTable

Checks if the specified table exists in the database.

hasView

Checks if the specified view exists in the database.

getTables

Retrieves an array of all tables in the database.

getViews

Retrieves an array of all views in the database.

getTypes

Retrieves an array of all column types supported by the database.

hasColumn

Checks if the specified table has a specific column.

hasColumns

Checks if the specified table has all of the specified columns.

whenTableHasColumn

Executes a callback if a specific column exists in the specified table.

whenTableDoesntHaveColumn

Executes a callback if a specific column does not exist in the specified table.

getColumnType

Retrieves the type of the specified column in the specified table.

getColumnListing

Retrieves an array of column names for the specified table.

getColumns

Retrieves an array of column definitions for the specified table.

getIndexes

Retrieves an array of indexes for the specified table.

getForeignKeys

Retrieves an array of foreign keys for the specified table.

table

Allows for modifying a table using a closure callback.

create

Creates a new table using a closure callback.

drop

Drops the specified table.

dropIfExists

Drops the specified table if it exists.

dropColumns

Drops the specified columns from the specified table.

dropAllTables

Drops all tables in the database.

dropAllViews

Drops all views in the database.

dropAllTypes

Drops all column types supported by the database.

rename

Renames a table from the specified name to another name.

enableForeignKeyConstraints

Enables foreign key constraints.

disableForeignKeyConstraints

Disables foreign key constraints.

withoutForeignKeyConstraints

Executes a callback without foreign key constraints.

getConnection

Retrieves the underlying database connection.

setConnection

Sets the database connection to be used.

blueprintResolver

Sets the blueprint resolver for creating tables.

Classes

None

<?php

namespace Illuminate\Support\Facades;

/**
 * @method static void defaultStringLength(int $length)
 * @method static void defaultMorphKeyType(string $type)
 * @method static void morphUsingUuids()
 * @method static void morphUsingUlids()
 * @method static void useNativeSchemaOperationsIfPossible(bool $value = true)
 * @method static bool createDatabase(string $name)
 * @method static bool dropDatabaseIfExists(string $name)
 * @method static bool hasTable(string $table)
 * @method static bool hasView(string $view)
 * @method static array getTables()
 * @method static array getViews()
 * @method static array getTypes()
 * @method static bool hasColumn(string $table, string $column)
 * @method static bool hasColumns(string $table, array $columns)
 * @method static void whenTableHasColumn(string $table, string $column, \Closure $callback)
 * @method static void whenTableDoesntHaveColumn(string $table, string $column, \Closure $callback)
 * @method static string getColumnType(string $table, string $column, bool $fullDefinition = false)
 * @method static array getColumnListing(string $table)
 * @method static array getColumns(string $table)
 * @method static array getIndexes(string $table)
 * @method static array getForeignKeys(string $table)
 * @method static void table(string $table, \Closure $callback)
 * @method static void create(string $table, \Closure $callback)
 * @method static void drop(string $table)
 * @method static void dropIfExists(string $table)
 * @method static void dropColumns(string $table, string|array $columns)
 * @method static void dropAllTables()
 * @method static void dropAllViews()
 * @method static void dropAllTypes()
 * @method static void rename(string $from, string $to)
 * @method static bool enableForeignKeyConstraints()
 * @method static bool disableForeignKeyConstraints()
 * @method static mixed withoutForeignKeyConstraints(\Closure $callback)
 * @method static \Illuminate\Database\Connection getConnection()
 * @method static \Illuminate\Database\Schema\Builder setConnection(\Illuminate\Database\Connection $connection)
 * @method static void blueprintResolver(\Closure $resolver)
 *
 * @see \Illuminate\Database\Schema\Builder
 */
class Schema extends Facade
{
    /**
     * Indicates if the resolved facade should be cached.
     *
     * @var bool
     */
    protected static $cached = false;

    /**
     * Get a schema builder instance for a connection.
     *
     * @param  string|null  $name
     * @return \Illuminate\Database\Schema\Builder
     */
    public static function connection($name)
    {
        return static::$app['db']->connection($name)->getSchemaBuilder();
    }

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'db.schema';
    }
}