PHP code example of roskiboy / orm-universal-laravel
1. Go to this page and download the library: Download roskiboy/orm-universal-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/ */
roskiboy / orm-universal-laravel example snippets
use OrmUniversal\Laravel\Facades\OrmUniversal;
use OrmUniversal\Relational\Ast\Column;
// Vanilla Eloquent keeps working unchanged.
$eloquent = App\Models\Seller::query()->orderBy('name')->pluck('name');
// The same result through the universal engine.
$ude = OrmUniversal::table('sellers')
->where(Column::make('is_active')->eq(true))
->orderBy('name')
->recordset();
use OrmUniversal\Relational\Ast\Column;
use OrmUniversal\Relational\Ast\SelectQuery;
use OrmUniversal\Relational\Dialect\PostgreSqlDialect;
$dialect = PostgreSqlDialect::make('18.0');
$query = SelectQuery::make('orders')
->select('id', 'total')
->where(Column::make('total')->gte(100))
->orderByDesc('total')
->limit(50);
$compiled = $dialect->compile($query);
echo $compiled->sql; // SQL with quoted identifiers
$compiled->bindings; // [100]
(string) $compiled->fingerprint(); // query identity
use OrmUniversal\Laravel\Concerns\HasUniversalQueries;
class Seller extends Model
{
use HasUniversalQueries;
}
Seller::universal()->where('is_active', true)->get();
Seller::query()->recordset(); // global macro, does not alter results