https://github.com/codexshaper/php-database
Laravel database and eloquent for php project.
https://github.com/codexshaper/php-database
database eloquent migration orm php
Last synced: 3 months ago
JSON representation
Laravel database and eloquent for php project.
- Host: GitHub
- URL: https://github.com/codexshaper/php-database
- Owner: Codexshaper
- License: mit
- Created: 2020-06-05T06:31:49.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-05T07:24:51.000Z (about 5 years ago)
- Last Synced: 2025-03-25T05:02:20.457Z (4 months ago)
- Topics: database, eloquent, migration, orm, php
- Language: PHP
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://badges.mit-license.org)
[](https://travis-ci.org/Codexshaper/php-database)
[](https://github.styleci.io/repos/269548874)
[](https://scrutinizer-ci.com/g/Codexshaper/php-database)
[](https://packagist.org/packages/Codexshaper/php-database)
[](https://packagist.org/packages/Codexshaper/php-database)# Database and ORM
Laravel database and eloquent for php project.## Download
```
composer require codexshaper/php-database
```## Setup root facade
```
use Illuminate\Support\Facades\Facade;
use Illuminate\Container\Container;Facade::setFacadeApplication(new Container);
```Note: If you alraedy setup `container` as a root facade then leave it.
## Create a new connection
```
use CodexShaper\Database\Database;
```
### Using `constructor`
```
$db = new Database([
"driver" => "mysql",
"host" => 'localhost',
"database" => 'db_name',
"username" => 'db_user',
"password" => 'db_password',
"prefix" => 'db_prefix',
"charset" => 'utf8mb4',
"collation" => 'utf8mb4_unicode_ci',
]);
```
### Using `addConnection` method```
$db = new Database;
$db->addConnection([
"driver" => "mysql",
"host" => 'localhost',
"database" => 'laravel-woocommerce',
"username" => 'root',
"password" => '',
"prefix" => 'wp_',
"charset" => 'utf8mb4',
"collation" => 'utf8mb4_unicode_ci',
]);
```## Finaly `run` database to use globally and setup eloquent orm
```
$db->run();
```## Create a table
```
use CodexShaper\Database\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
```## Drop a table
```
use CodexShaper\Database\Facades\Schema;
Schema::dropIfExists('custom_options');
```