PHP code example of litebase / litebase-laravel

1. Go to this page and download the library: Download litebase/litebase-laravel 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/ */

    

litebase / litebase-laravel example snippets


'connections' => [
    // ... other connections
    
    'litebase' => [
        'driver' => 'litebase',
        'database' => env('LITEBASE_DATABASE', 'your_database/main'),
        'host' => env('LITEBASE_HOST', 'localhost'),
        'port' => env('LITEBASE_PORT', '8888'),
        'access_key_id' => env('LITEBASE_ACCESS_KEY_ID'),
        'access_key_secret' => env('LITEBASE_ACCESS_KEY_SECRET'),
    ],
],

use Illuminate\Support\Facades\DB;

// Select
$users = DB::connection('litebase')
    ->table('users')
    ->where('active', true)
    ->get();

// Insert
DB::connection('litebase')
    ->table('users')
    ->insert([
        'name' => 'John Doe',
        'email' => '[email protected]',
    ]);

// Update
DB::connection('litebase')
    ->table('users')
    ->where('id', 1)
    ->update(['name' => 'Jane Doe']);

// Delete
DB::connection('litebase')
    ->table('users')
    ->where('id', 1)
    ->delete();

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $connection = 'litebase';
    protected $table = 'users';
}

// Use the model
$user = User::create([
    'name' => 'John Doe',
    'email' => '[email protected]',
]);

$users = User::where('active', true)->get();

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    protected $connection = 'litebase';
    
    public function up()
    {
        Schema::connection('litebase')->create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->boolean('active')->default(true);
            $table->timestamps();
        });
    }
    
    public function down()
    {
        Schema::connection('litebase')->dropIfExists('users');
    }
};

use Illuminate\Support\Facades\Schema;

// Check if table exists
if (Schema::connection('litebase')->hasTable('users')) {
    // ...
}

// Get all tables
$tables = Schema::connection('litebase')->getTables();

// Get table columns
$columns = Schema::connection('litebase')->getColumns('users');

use Illuminate\Support\Facades\DB;

DB::connection('litebase')->transaction(function () {
    DB::connection('litebase')
        ->table('users')
        ->insert(['name' => 'John Doe', 'email' => '[email protected]']);
    
    DB::connection('litebase')
        ->table('logs')
        ->insert(['action' => 'user_created']);
});
bash
php artisan migrate --database=litebase
bash
php artisan litebase:db [connection?]