1. Go to this page and download the library: Download pollora/colt 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/ */
pollora / colt example snippets
use Pollora\Colt\Model\Post;
// All published posts
$posts = Post::published()->get();
// A specific post, its title and a custom field
$post = Post::find(31);
echo $post->title; // alias of post_title
echo $post->meta->link; // value of the "link" post meta
// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();
// A specific post
$post = Post::find(31);
echo $post->post_title;
namespace App\Models;
use Pollora\Colt\Model\Post as ColtPost;
class Post extends ColtPost
{
protected $connection = 'foo-bar';
public function customMethod()
{
//
}
}
$posts = App\Models\Post::all(); // uses the 'foo-bar' connection
$post = Post::find(31);
echo $post->meta->link; // or
echo $post->fields->link; // or
echo $post->link;
$post = Post::find(1);
$post->saveMeta('username', 'jgrossi');
// Several at once
$post->saveMeta([
'username' => 'jgrossi',
'url' => 'http://jgrossi.com',
]);
// A published post that has a meta key
$post = Post::published()->hasMeta('featured_article')->first();
// Matching both key and value
$post = Post::published()->hasMeta('username', 'jgrossi')->first();
// Several fields, or just several keys
$post = Post::hasMeta(['username' => 'jgrossi'])->first();
$post = Post::hasMeta(['username' => 'jgrossi', 'url' => 'jgrossi.com'])->first();
$post = Post::hasMeta(['username', 'url'])->first();
// With type()
$videos = Post::type('video')->status('publish')->get();
// With your own class
class Video extends \Pollora\Colt\Model\Post
{
protected $postType = 'video';
}
$videos = Video::status('publish')->get();
$stores = Post::type('store')->status('publish')->take(3)->get();
foreach ($stores as $store) {
$storeAddress = $store->address; // or $store->meta->address, or $store->fields->address
}
Post::registerPostType('video', App\Models\Video::class);
// Every item is now a Video instance
$videos = Post::type('video')->status('publish')->get();
use Pollora\Colt\Model\Page;
$page = Page::slug('about')->first(); // or
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;
// Taxonomies of a post
$post = Post::find(1);
$taxonomy = $post->taxonomies()->first();
echo $taxonomy->taxonomy;
// Posts in a term
$post = Post::taxonomy('category', 'php')->first();
// A category and its posts
$category = Taxonomy::category()->slug('uncategorized')->first();
$category->posts->each(function ($post) {
echo $post->post_title;
});
// All categories with their posts
$categories = Taxonomy::where('taxonomy', 'category')->with('posts')->get();
echo $post->getFormat(); // 'video', etc.
$page = Page::slug('about')->with('attachment')->first();
print_r($page->attachment); // featured image
$post = Post::slug('test')->with('revision')->first();
print_r($post->revision); // all revisions
$post = Post::find(1);
// A Pollora\Colt\Model\Meta\ThumbnailMeta instance
print_r($post->thumbnail);
// Cast to string, it is the URL of the original image
echo $post->thumbnail;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class FooShortcode implements \Pollora\Colt\Shortcode
{
public function render(ShortcodeInterface $shortcode)
{
return sprintf(
'html-for-shortcode-%s-%s',
$shortcode->getName(),
$shortcode->getParameter('one')
);
}
}
$menu = Menu::slug('primary')->first();
foreach ($menu->items as $item) {
echo $item->instance()->title; // a Post
echo $item->instance()->name; // a Term
echo $item->instance()->link_text; // a custom link
}
use Pollora\Colt\Laravel\Auth\ResetsPasswords as ColtResetsPasswords;
class ResetPasswordController extends Controller
{
use ResetsPasswords, ColtResetsPasswords {
ColtResetsPasswords::resetPassword insteadof ResetsPasswords;
}
}
$userProvider = new Pollora\Colt\Laravel\Auth\AuthUserProvider;
$user = $userProvider->retrieveByCredentials(['username' => 'admin']);
if (! is_null($user) && $userProvider->validateCredentials($user, ['password' => 'admin'])) {
// logged in
}