PHP code example of envor / laravel-schema-macros

1. Go to this page and download the library: Download envor/laravel-schema-macros library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

envor / laravel-schema-macros example snippets


use Illuminate\Support\Facades\Schema;

$database = database_path('my-new-database.sqlite');

Schema::connection('sqlite')->databaseExists($database);

// false

touch($database);

Schema::connection('sqlite')->databaseExists($database);

// true

Schema::connection('mysql')->databaseExists('abc');

// false

Schema::connection('mysql')->createDatabase('abc');


Schema::connection('mysql')->databaseExists('abc');

// true


use Illuminate\Support\Facades\Schema;

$default = database_path('database.sqlite');

touch($default);

Schema::connection('sqlite')->createDatabaseIfNotExists($default);

// false

Schema::connection('sqlite')->createDatabaseIfNotExists(database_path('another_database'));

// true


Schema::connection('mysql')->createDatabaseIfNotExists('brand_new_database');

// true



$newFile = database_path('/new/directories/will/be/created/recursively/db.sqlite');

Schema::connection('sqlite')->createDatabaseIfNotExists($newFile);

// true

$database = database_path('database.sqlite');

Schema::connection('sqlite')->trashDatabase($database);

// /home/forge/mysite.com/storage/app/.trash/2024-02-04_06-29-11_database.sqlite

Schema::connection('mariadb')->trashDatabase('schema_demo');

// trashed_2024-02-04_06-44-42_schema_demo

$database = database_path('database.sqlite');

Schema::connection('sqlite')->trashDatabase($database);

// /home/forge/mysite.com/storage/app/.trash/2024-02-04_06-29-11_database.sqlite

Schema::connection('sqlite')->emptyTrash();

// 1

Schema::connection('mysql')->trashDatabase('schema_demo');

// trashed_2024-02-04_06-44-42_schema_demo

Schema::connection('mysql')->emptyTrash();

// 1

$database = database_path('database.sqlite');

Schema::connection('sqlite')->copyTable('users');

// users_copy

Schema::connection('sqlite')->copyTable('users', 'users_snapshot_1');

// users_snapshot_1