PHP code example of javaabu / cms

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

    

javaabu / cms example snippets


use Javaabu\Cms\Enums\PostTypeFeatures;
use Javaabu\Cms\PostTypes\PostType;

'default_post_types' => [
    PostType::make('news')
        ->name('News')
        ->singularName('News Article')
        ->icon('zmdi-assignment')
        ->categoryType('news-categories')
        ->feature(PostTypeFeatures::CATEGORIES)
        ->feature(PostTypeFeatures::IMAGE_GALLERY)
        ->feature('featured-image')
        ->feature('excerpt')
        ->description('Latest news and updates'),

    PostType::make('blog')
        ->name('Blog Posts')
        ->singularName('Blog Post')
        ->icon('zmdi-library')
        ->categoryType('blog-categories')
        ->features(
            PostTypeFeatures::CATEGORIES,
            PostTypeFeatures::IMAGE_GALLERY,
            'featured-image',
            'excerpt',
            'video-link',
        ),
],

'category_types' => [
    'news-categories' => [
        'label' => 'News Categories',
        'singular_label' => 'News Category',
        'hierarchical' => true,
    ],
],

use Javaabu\Cms\Support\Routes;

// Admin routes
Routes::admin(
    prefix: 'admin',
    middleware: ['web', 'auth', 'verified']
);

// Public routes
Routes::web();

// Or register custom post type routes
Routes::customPostType(
    postTypeSlug: 'news',
    prefix: 'news',
    middleware: ['web']
);

use Javaabu\Cms\Models\PostType;

PostType::create([
    'name' => 'News',
    'singular_name' => 'News Article',
    'slug' => 'news',
    'icon' => 'newspaper',
    'features' => [
        'categories' => true,
        'featured_image' => true,
        'excerpt' => true,
    ],
]);

use Javaabu\Cms\Models\Post;
use Javaabu\Cms\Enums\PostStatus;

$post = Post::create([
    'type' => 'news',
    'title' => 'Breaking News',
    'slug' => 'breaking-news',
    'content' => '<p>Content here...</p>',
    'excerpt' => 'Short description',
    'status' => PostStatus::PUBLISHED->value,
    'published_at' => now(),
]);

// Attach categories
$post->categories()->attach($categoryIds);

use Javaabu\Cms\Models\Post;

// Get published posts of a type
$posts = Post::postType('news')
    ->published()
    ->ordered()
    ->paginate(15);

// Search posts
$posts = Post::postType('news')
    ->search('keyword')
    ->published()
    ->get();

// Get posts by year
$posts = Post::postType('news')
    ->publishedByYear(2024)
    ->get();

use Javaabu\Cms\Models\Category;

// Get categories for select dropdown
$categories = Category::categoryList($typeId);

// Get nested categories
$categories = Category::categoryType($typeId)
    ->defaultOrder()
    ->get()
    ->toTree();

use Javaabu\Cms\seeders\CmsPermissionsSeeder;

CmsPermissionsSeeder::seedPermissions();
bash
php artisan cms:setup
bash
php artisan cms:setup --with-defaults
blade
{{-- resources/views/posts/index.blade.php --}}
@foreach($posts as $post)
    <article>
        <h2>{{ $post->title }}</h2>
        <p>{{ $post->excerpt }}</p>
        <a href="{{ route('posts.show', [$post->type, $post->slug]) }}">
            Read More
        </a>
    </article>
@endforeach