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/ */
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');
}
}