PHP code example of velt / orm

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

    

velt / orm example snippets


User::find(1);
User::where('email', $email)->first();
$user->save();

use Velt\Orm\Model;

final class User extends Model
{
    protected static string $table = 'users';

    protected static array $fillable = ['name', 'email'];
}

$user = User::find(1);
$user = User::where('email', $email)->first();

$user = new User(['name' => 'Ada', 'email' => '[email protected]']);
$user->save();

$user->name = 'Ada Lovelace';
$user->save();

$user->delete();

final class User extends Model
{
    protected static string $table = 'users';

    public function posts(): array
    {
        return $this->hasMany(Post::class, 'user_id');
    }
}

final class Post extends Model
{
    protected static string $table = 'posts';

    public function user(): ?Model
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}

$page = User::query()->orderBy('id')->paginate(page: 1, perPage: 15);

$page->toArray();

[
    'data' => [...],
    'page' => 1,
    'total' => 50,
    'perPage' => 15,
]