1. Go to this page and download the library: Download wpmvc/database 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/ */
wpmvc / database example snippets
namespace WpMVC\App\Models;
use WpMVC\Database\Eloquent\Model;
use WpMVC\Database\Resolver;
class Post extends Model {
public static function get_table_name():string {
return 'posts';
}
public function resolver():Resolver {
return new Resolver;
}
}
namespace WpMVC\App\Models;
use WpMVC\Database\Eloquent\Model;
use WpMVC\Database\Eloquent\Relations\HasOne;
class User extends Model {
/**
* Get the phone associated with the user.
*/
public function phone(): HasOne
{
return $this->has_one(Phone::class, 'ID', 'user_id');
}
}
$users = User::query()->with('phone')->get();
namespace WpMVC\App\Models;
use WpMVC\Database\Eloquent\Model;
use WpMVC\Database\Eloquent\Relations\HasMany;
class Post extends Model {
/**
* Get the all meta associated with the user.
*/
public function meta(): HasMany
{
return $this->has_many(PostMeta::class, 'ID', 'post_id');
}
}
namespace WpMVC\App\Models;
use WpMVC\Database\Eloquent\Model;
use WpMVC\Database\Eloquent\Relations\BelongsToOne;
class PostMeta extends Model {
/**
* Get the post that owns the meta.
*/
public function post(): BelongsToOne
{
return $this->belongs_to_one(Post::class, 'post_id', 'ID');
}
}