redbeed/corcel-laravel5
Composer 安装命令:
composer require redbeed/corcel-laravel5
包简介
Wrappers to collect data from Wordpress databases with Laravel 5
README 文档
README
This is a fork of jgrossi/corcel
--
Corcel is a class collection created to retrieve Wordpress database data using a better syntax. It uses the Eloquent ORM developed for the Laravel 5 Framework.
This way you can use Wordpress as back-end, to insert posts, custom types, etc.
Installation
To install Corcel just create a composer.json file and add:
"require": {
"redbeed/corcel-laravel5": "dev-master"
},
After that run composer update and wait.
Usage
First you must add the service provider to to config/app.php under providers
Corcel\CorcelServiceProvider::class
Now you must publish the assets:
php artisan vendor:publish
You can specify the connection in the corcel config file.
config/corcel.php
Posts
// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();
// A specific post
$post = Post::find(31);
echo $post->post_title;
You can retrieve meta data from posts too.
// Get a custom meta value (like 'link' or whatever) from a post (any type)
$post = Post::find(31);
echo $post->meta->link; // OR
echo $post->fields->link;
echo $post->link; // OR
Updating post custom fields:
$post = Post::find(1);
$post->meta->username = 'juniorgrossi';
$post->meta->url = 'http://grossi.io';
$post->save();
Inserting custom fields:
$post = new Post;
$post->save();
$post->meta->username = 'juniorgrossi';
$post->meta->url = 'http://grossi.io';
$post->save();
Custom Post Type
You can work with custom post types too. You can use the type(string) method or create your own class.
// using type() method
$videos = Post::type('video')->status('publish')->get();
// using your own class
class Video extends Corcel\Post
{
protected $postType = 'video';
}
$videos = Video::status('publish')->get();
Custom post types and meta data:
// Get 3 posts with custom post type (store) and show its title
$stores = Post::type('store')->status('publish')->take(3)->get();
foreach ($stores as $store) {
$storeAddress = $store->address; // option 1
$storeAddress = $store->meta->address; // option 2
$storeAddress = $store->fields->address; // option 3
}
Taxonomies
You can get taxonomies for a specific post like:
$post = Post::find(1);
$taxonomy = $post->taxonomies()->first();
echo $taxonomy->taxonomy;
Or you can search for posts using its taxonomies:
$post = Post::taxonomy('category', 'php')->first();
Pages
Pages are like custom post types. You can use Post::type('page') or the Page class.
// Find a page by slug
$page = Page::slug('about')->first(); // OR
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;
Categories & Taxonomies
Get a category or taxonomy or load posts from a certain category. There are multiple ways to achief it.
// all categories
$cat = Taxonomy::category()->slug('uncategorized')->posts()->first();
echo "<pre>"; print_r($cat->name); echo "</pre>";
// only all categories and posts connected with it
$cat = Taxonomy::where('taxonomy', 'category')->with('posts')->get();
$cat->each(function($category) {
echo $category->name;
});
// clean and simple all posts from a category
$cat = Category::slug('uncategorized')->posts()->first();
$cat->posts->each(function($post) {
echo $post->post_title;
});
Attachment and Revision
Getting the attachment and/or revision from a Post or Page.
$page = Page::slug('about')->with('attachment')->first();
// get feature image from page or post
print_r($page->attachment);
$post = Post::slug('test')->with('revision')->first();
// get all revisions from a post or page
print_r($post->revision);
Licence
Corcel is licensed under the MIT license.
redbeed/corcel-laravel5 适用场景与选型建议
redbeed/corcel-laravel5 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.64k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 redbeed/corcel-laravel5 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 redbeed/corcel-laravel5 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-25