1. Go to this page and download the library: Download vinhnguyen/corcel 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/ */
$params = array(
'database' => 'database_name',
'username' => 'username',
'password' => 'pa$$word',
'prefix' => 'wp_' // default prefix is 'wp_', you can change to your own prefix
);
Corcel\Database::connect($params);
'driver' => 'mysql',
'host' => 'localhost',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'wp_', // Specify the prefix for WordPress tables, default prefix is 'wp_'
// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();
// A specific post
$post = Post::find(31);
echo $post->post_title;
// File: app/Post.php
namespace App;
use Corcel\Model\Post as Corcel;
class Post extends Corcel
{
protected $connection = 'foo-bar';
public function customMethod() {
//
}
}
$posts = App\Post::all(); // using the 'foo-bar' connection
// 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
// 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();
// Get 3 posts with custom post type (store) and show its address
$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
}
//all objects in the $videos Collection will be instances of Post
$videos = Post::type('video')->status('publish')->get();
// register the video custom post type and its particular class
Post::registerPostType('video', '\App\Video')
//now all objects in the $videos Collection will be instances of Video
$videos = Post::type('video')->status('publish')->get();
echo $post->getFormat(); // should return something like 'video', etc
use Corcel\Model\Page;
// Find a page by slug
$page = Page::slug('about')->first(); // OR
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;
// 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;
});
$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);
$post = Post::find(1);
// Retrieve an instance of Corcel\Model\Meta\ThumbnailMeta.
print_r($post->thumbnail);
// For convenience you may also echo the thumbnail instance to get the URL of the original image.
echo $post->thumbnail;
$menu = Menu::slug('primary')->first();
foreach ($menu->items as $item) {
echo $item->instance()->title; // if it's a Post
echo $item->instance()->name; // if it's a Term
echo $item->instance()->link_text; // if it's a custom link
}
$items = Menu::slug('foo')->first()->items;
$parent = $items->first()->parent(); // Post, Page, CustomLink or Term (category)
// All users
$users = User::get();
// A specific user
$user = User::find(1);
echo $user->user_login;
'providers' => [
// Other Service Providers
Corcel\Laravel\CorcelServiceProvider::class,
],
Auth::validate([
'email' => '[email protected]', // or using 'username' too
'password' => 'secret',
]);
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
use ResetsPasswords;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Corcel\Laravel\Auth\ResetsPasswords as CorcelResetsPasswords;
class PasswordController extends Controller
{
use ResetsPasswords, CorcelResetsPasswords {
CorcelResetsPasswords::resetPassword insteadof ResetsPasswords;
}