PHP code example of darkterminal / turso-http-laravel

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

    

darkterminal / turso-http-laravel example snippets


return [
    App\Providers\AppServiceProvider::class,
    Turso\Http\Laravel\LibSQLHttpServiceProvider::class, // Here
];

'libsql' => [
    'driver' => 'libsql',
    'url' => env('DB_DATABASE', ''),
    'authToken' => env('DB_AUTH_TOKEN', ''),
    'database' => null,
    'prefix' => '',
],

use Illuminate\Support\Facades\DB;

// Create
DB::table('users')->insert([
    'name' => 'Budi Dalton',
    'email' => '[email protected]'
]);

// Read
DB::table('users')->get();
DB::table('users')->where('id', 2)->first();
DB::table('users')->orderBy('id', 'DESC')->limit(2)->get();

// Update
DB::table('users')->where('id', 2)->update(['name' => 'Doni Mandala']);

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

// Transaction
try {
    DB::beginTransaction();

    $updated = DB::table('users')->where('id', 9)->update(['name' => 'Doni Kumala']);

    if ($updated) {
        echo "It's updated";
        DB::commit();
    } else {
        echo "Not updated";
        DB::rollBack();
    }

    $data = DB::table('users')->orderBy('id', 'DESC')->limit(2)->get();
    dump($data);
} catch (\Exception $e) {
    DB::rollBack();
    echo "An error occurred: " . $e->getMessage();
}