PHP code example of orchid / cms

1. Go to this page and download the library: Download orchid/cms 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/ */

    

orchid / cms example snippets


// Create entity for one record
php artisan orchid:entity-single   

// Create entity for many records
php artisan orchid:entity-many

namespace DummyNamespace;

use Orchid\Press\Entities\Many;

class DummyClass extends Many
{

    /**
     * @var string
     */
    public $name = '';

    /**
     * @var string
     */
    public $slug = '';

    /**
     * @var string
     */
    public $icon = '';

    /**
     * Slug url /news/{name}.
     * @var string
     */
    public $slugFields = '';

    /**
     * Rules Validation.
     * @return array
     */
    public function rules()
    {
        return [];
    }

    /**
     * @return array
     */
    public function fields()
    {
        return [];
    }

    /**
     * Grid View for post type.
     */
    public function grid()
    {
        return [];
    }

    /**
     * @return array
     */
    public function options()
    {
        return [];
    }
}


 /**
  * Grid View for post type.
  */
 public function grid()
 {
     return [
         TD::set('name','Name'),
         TD::set('publish_at','Date of publication'),
         TD::set('created_at','Date of creation'),
         TD::name('full_name','Full name')->render(function($post){
             return  "{$post->getContent('fist_name')} {$post->getContent('last_name')}";
         })
     ];
 }


use Orchid\Press\Models\Post;

$posts = Post::all();

// All posted posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();

// Specific entry
$post = Post::find(42);

// Post name based on the current localization
echo $post->getContent('name');


// Specific entry
$post = Post::find(42);

// All options
echo $post->getOptions();

// Get all localization parameters from options
echo $post->getOption('locale');

// If the option does not exist or is not specified
// you can specify the second parameter that will be returned.
echo $post->getOption('countPlace',10);


//All objects in the $videos collection will be Post instances
$videos = Post::type('video')->status('publish')->get();

$post = Post::find(42);
$taxonomy = $post->taxonomies()->first();
echo $taxonomy->taxonomy;

$post = Post::taxonomy('category', 'php')->first();

$posts  = Post::whereHas('taxonomies.term', function($query){
	$query->whereIn('slug',
	    Category::slug('main')->with('childrenTerm')
	    ->first()->childrenTerm->pluck('term.slug')
	);
})->get()

// All categories
$category = Taxonomy::category()->slug('uncategorized')->posts()->first();


// Only all categories and entries associated with it
$category = Taxonomy::where('taxonomy', 'category')->with('posts')->get();
$category->each(function($category) {
    echo $category->term->getContent('name');
});

// all posts from category
$category = Category::slug('uncategorized')->posts()->first();
$category->posts->each(function($post) {
    echo $post->getContent('name');
});

$item = Post::find(42);
$image->attachment()->first();
$image->url();

/**
 * Get the indexable data array for the model.
 *
 * @param $array
 *
 * @return mixed
 */
public function toSearchableArray($array)
{
    // Customize array...

    return $array;
}

/**
 * Get the indexable data array for the model.
 *
 * @param $array
 *
 * @return mixed
 */
public function toSearchableArray($array)
{
    $array['content']['en']['id'] = $array['id'];

    return $array['content']['en'];
}

php artisan scout:import Orchid\\Press\\Models\\Post

use Orchid\Press\Models\Post;
$articles = Post::search('как пропатчить kde2 под freebsd')->get();

use Orchid\Press\TraitsTaggableTrait;

class Product extends Eloquent
{
    use TaggableTrait;
}

use Orchid\Press\Models\Post;

// Get the entity object
$post = Post::find(1);

// Through a string
$post->tag('foo, bar, baz');

// Through an array
$post->tag([ 'foo', 'bar', 'baz']);

// Get the entity object
$post = post::find(1);

// Through a string
$post->untag('bar, baz');

// Through an array
$post->untag(['bar', 'baz']);

// Remove all the tags
$post->untag();

// Get the entity object
$post = Post::find(1);

// Through a string
$post->setTags('foo, bar, baz');

// Through an array
$post->setTags(['foo', 'bar', 'baz']);

// Using the `slug` column
$post->setTags(['foo', 'bar', 'baz'], 'slug');

// Get the entity object
$post = Post::whereTag('foo, bar')->get();


$post = Post::find(1);
$tags = $post->tags;

$tags = Post::allTags();

use Orchid\Press\Models\Comment;
use Orchid\Press\Models\Post;

$post = Post::find(42);

$comment = Comment::create([
    'post_id'   => $post->id,
    'user_id'   => Auth::id(),
    'parent_id' => 0,
    'content'   => 'Any text',
    'approved'  => 1,
]);



// Retrieve all comments for a specific Post
$comments = Comment::findByPostId(42);


$comment = Comment::find(1);

// Get in touch with Post
$post = $comment->post();

// Get parent comment
$comment = $comment->original();

// Get child comments
$comment = $comment->replies();

// Get the author of the comment
$comment = $comment->author();


$comment = Comment::find(1);


// Check if a comment has been posted
$comment->isApproved();

// Check if a comment is a response to another comment
$comment->isReply();

// Check if the comment has answers
$comment->hasReplies();

'menu' => [
    'header'  => 'Top Menu',
    'sidebar' => 'Sidebar Menu',
    'footer'  => 'Footer Menu',
],

namespace Orchid\Press\Models\Menu;

$menu = Menu::where('lang', app()->getLocale()())
    ->where('parent',0)
    ->where('type', 'footer')
    ->with('children')
    ->get();

//First child
$menu = Menu::find(1)->children()->first();


//Parent element
$menu = Menu::find(1)->parent()->get();