Download the PHP package wenprise/eloquent without Composer
On this page you can find all versions of the php package wenprise/eloquent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent
Credits
Thanks to:
Eloquent Wrapper for WordPress
This is a library package to use Laravel's Eloquent ORM with WordPress.
How it Works
- Eloquent is mainly used here as the query builder
- WPDB is used to run queries built by Eloquent
- Hence, we have the benfit to use plugins like
debug-bar
orquery-monitor
to get SQL query reporting. - It doesn't create any extra MySQL connection
Minimum Requirement
- PHP 7.0
- WordPress 3.6+
Package Installation
$ composer require wenprise/eloquent
Usage Example
Basic Usage
Posts
Pages
Pages are like custom post types. You can use Post::type('page')
or the Wenprise\ORM\WP\Page
class.
Comments
Meta Data (Custom Fields)
You can retrieve meta data from posts too.
To create or update meta data form a User just use the saveMeta()
or saveField()
methods. They return bool
like the Eloquent save()
method.
You can save many meta data at the same time too:
You also have the createMeta()
and createField()
methods, that work like the saveX()
methods, but they are used only for creation and return the PostMeta
created instance, instead of bool
.
Querying Posts by Custom Fields (Meta)
There are multiples possibilities to query posts by their custom fields (meta). Just use the hasMeta()
scope under Post
(actually for all models using the HasMetaFields
trait) class:
You can also use the hasMeta()
scope passing an array as parameter:
Fields Aliases
The Post
class has support to "aliases", so if you check the Post
class you should note some aliases defined in the static $aliases
array, like title
for post_title
and content
for post_content
.
If you're extending the Post
class to create your own class you can use $aliases
too. Just add new aliases to that static property inside your own class and it will automatically inherit all aliases from parent Post
class:
Custom Scopes
To order posts you can use newest()
and oldest()
scopes, for both Post
and User
classes:
Pagination
To order posts just use Eloquent paginate()
method:
To display the pagination links just call the links()
method:
Post Taxonomies
You can get taxonomies for a specific post like:
Or you can search for posts using its taxonomies:
Categories and Taxonomies
Get a category or taxonomy or load posts from a certain category. There are multiple ways to achieve it.
Attachment and Revision
Getting the attachment and/or revision from a Post
or Page
.
Users
You can manipulate users in the same manner you work with posts:
Options
You can use the Option
class to get data from wp_options
table:
You can also add new options:
You can get all options in a simple array:
Or you can specify only the keys you want to get:
Writing a Model
The class name Employee
will be translated into PREFIX_employees
table to run queries. But as usual, you can override the table name.