1. Go to this page and download the library: Download tamedevelopers/database 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/ */
tamedevelopers / database example snippets
use Tamedevelopers\Database\AutoLoader;
AutoLoader::start();
// then reload your browser to allow the system scalfold for you
use Tamedevelopers\Support\Capsule\Artisan;
Artisan::call('db:wipe --force');
use Tamedevelopers\Database\Capsule\AppManager;
AppManager::bootLoader();
// app_manager()->bootLoader();
DB::connection('connName', $options);
DB::disconnect('connName');
DB::reconnect('connName', $options);
$db = DB::connection();
$db->table('users');
DB::table('users')->insert([
'user_id' => 10000001,
'first_name' => 'Alfred',
'last_name' => 'Pete',
'wallet_bal' => 0.00,
'registered' => strtotime('now'),
]);
-- To see data, you need to save into a variable
$users = DB::table('users')
->paginate(40);
$users // this will return the data objects
$users->links() // this will return the paginations links view
$users->showing() // Display items of total results
use Tamedevelopers\Database\Auth;
$admin = Auth::guard('admins');
use Tamedevelopers\Database\Auth;
// Create guards
$admin = (new Auth)->guard('tb_admin');
$user = (new Auth)->guard('tb_user', 'woocommerce');
// Credentials (password is ser->attempt($credentials)) {
// In-memory user available
$user->check(); // true
$user->id(); // e.g., 123
$user->user(); // full user array
}
// 2) Persist explicitly (similar to Laravel Auth::login())
$user->login($user->user()); // stores sanitized user in session (no password)
// 3) Retrieve later in another request
$another = (new Auth)->guard('tb_user', 'woocommerce');
$another->user(); // rehydrated from session
$another->check(); // true if session had user
// 4) Logout
$another->logout(); // clears in-memory and session
Migration::create('users');
Migration::create('users_wallet');
Migration::create('tb_jobs', 'jobs');
Migration::create('tb_sessions', 'sessions');
// migration()->create('users');
// Table `2023_04_19_1681860618_user` has been created successfully
// Table `2023_04_19_1681860618_user_wallet` has been created successfully
// Table `2023_04_19_1681860618_tb_jobs` has been created successfully
// Table `2023_04_19_1681860618_tb_sessions` has been created successfully
use Tamedevelopers\Database\Migrations\Schema;
Schema::defaultStringLength(200);
// schema()->defaultStringLength(2000);
use Tamedevelopers\Database\Migrations\Schema;
Schema::updateColumnDefaultValue('users_table', 'email_column', 'NOT NULL');
Schema::updateColumnDefaultValue('users_table', 'gender_column', []);
// or
// schema()->updateColumnDefaultValue('users_table', 'gender_column', []);
Migration::run();
or
migration()->run();
// Migration runned successfully on `2023_04_19_1681860618_user`
// Migration runned successfully on `2023_04_19_1681860618_user_wallet`
Migration::drop();
or
migration()->drop(true);
use Tamedevelopers\Database\Migrations\Schema;
Schema::dropTable('table_name');
or
schema()->dropTable('table_name');
use Tamedevelopers\Database\Migrations\Schema;
Schema::dropColumn('table_name', 'column_name');
or
schema()->dropColumn('table_name', 'column_name');
$db->getConfig()
$db->dbConnection()
$db->getDatabaseName()
$db->getPDO()
$db->getTablePrefix()
use Tamedevelopers\Database\DBImport;
$database = new DBImport('path_to/orm.sql', 'connName');
// new DBImport(base_path('path_to/orm.sql'))
// run the method
$status = $database->run();
// - Status code
// ->status == 404 (Failed to read file or File does'nt exists
// ->status == 400 (Query to database error
// ->status == 200 (Success importing to database
use Tamedevelopers\Database\Model;
class Post extends Model{
// define your custom model table name
protected $table = 'posts';
// -- You now have access to the DB public instances
public function getPost(){
return $this->select(['images', 'title', 'description'])->get();
}
}
bash
php tame list
bash
php tame scaffold:run --force
html
<div data-pagination-content>
<div class="wallet-container" data-pagination-append>
foreach($users as $user) {
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.