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
use WpMVC\Database\Schema;
Schema::create('products', function (Blueprint $table) {
$table->big_increments('id');
$table->unsigned_big_integer('category_id');
$table->string('title');
$table->long_text('description')->nullable();
$table->enum('visibility', ['publish', 'draft'])->default('publish');
$table->timestamps();
$table->foreign('category_id')
->references('id')
->on('categories')
->on_delete('cascade');
});
Schema::alter('products', function (Blueprint $table) {
$table->string('short_description')->after('title')->nullable();
$table->drop_column('legacy_column');
$table->drop_index('index_abc123');
});
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 {
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 {
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 {
public function post(): BelongsToOne {
return $this->belongs_to_one(Post::class, 'post_id', 'ID');
}
}
use WpMVC\Database\Query\Builder;
$posts = Post::query()->with([
'meta' => function (Builder $query) {
$query->where('meta_id', 672);
},
'user',
])->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.