|
1 | | -# Content Management System |
| 1 | +# Javaabu CMS |
2 | 2 |
|
3 | | -[](https://packagist.org/packages/javaabu/cms) |
4 | | -[](../../actions/workflows/run-tests.yml) |
5 | | - |
6 | | -[](https://packagist.org/packages/javaabu/cms) |
| 3 | +A flexible and extensible Content Management System package for Laravel applications. Built with support for custom post types, hierarchical categories, and rich content editing with Editor.js. |
7 | 4 |
|
| 5 | +## Features |
8 | 6 |
|
| 7 | +- 🎯 **Custom Post Types**: Define unlimited custom post types with configurable features |
| 8 | +- 📁 **Hierarchical Categories**: Nested category support using Nestedset |
| 9 | +- ✍️ **Rich Content Editor**: Integrated Editor.js support for modern content editing |
| 10 | +- 🔐 **Permission System**: Built-in permission management for CMS operations |
| 11 | +- 🌐 **Multi-language Ready**: Translation support for content |
| 12 | +- 📱 **Responsive Admin**: Modern admin interface |
| 13 | +- 🔌 **Extensible**: Easy to extend with custom controllers, views, and policies |
| 14 | +- 🚀 **Easy Setup**: Artisan command for quick installation |
9 | 15 |
|
10 | | -## Introduction |
11 | | -Content Management System integration for Laravel Projects |
| 16 | +## Requirements |
12 | 17 |
|
13 | | -## Documentation |
| 18 | +- PHP ^8.2 |
| 19 | +- Laravel ^11.0 or ^12.0 |
| 20 | +- MySQL/PostgreSQL database |
14 | 21 |
|
15 | | -You'll find the documentation on [https://docs.javaabu.com/docs/cms](https://docs.javaabu.com/docs/cms). |
| 22 | +## Installation |
16 | 23 |
|
17 | | -Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving this package? Feel free to create an [issue](../../issues) on GitHub, we'll try to address it as soon as possible. |
| 24 | +Install the package via Composer: |
18 | 25 |
|
19 | | -If you've found a bug regarding security please mail [info@javaabu.com](mailto:info@javaabu.com) instead of using the issue tracker. |
| 26 | +```bash |
| 27 | +composer require javaabu/cms |
| 28 | +``` |
20 | 29 |
|
| 30 | +Run the setup command: |
21 | 31 |
|
22 | | -## Testing |
| 32 | +```bash |
| 33 | +php artisan cms:setup |
| 34 | +``` |
| 35 | + |
| 36 | +This will: |
| 37 | +- Publish the configuration file |
| 38 | +- Publish and run migrations |
| 39 | +- Optionally install default post types and categories |
| 40 | +- Seed CMS permissions |
| 41 | + |
| 42 | +### Quick Start with Defaults |
23 | 43 |
|
24 | | -You can run the tests with |
| 44 | +To get started quickly with pre-configured post types and categories: |
25 | 45 |
|
26 | | -``` bash |
27 | | -./vendor/bin/phpunit |
| 46 | +```bash |
| 47 | +php artisan cms:setup --with-defaults |
28 | 48 | ``` |
29 | 49 |
|
30 | | -## Changelog |
| 50 | +This installs 10 ready-to-use post types (News, Blog, Downloads, Announcements, Publications, Jobs, Galleries, Tenders, Reports, Pages) with their category types and sample categories. |
31 | 51 |
|
32 | | -Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
| 52 | +You can customize these defaults in `config/cms.php` before running setup. |
33 | 53 |
|
34 | | -## Contributing |
| 54 | +## Configuration |
35 | 55 |
|
36 | | -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 56 | +After installation, configure your post types in `config/cms.php`: |
37 | 57 |
|
38 | | -## Security |
| 58 | +```php |
| 59 | +'post_types' => [ |
| 60 | + 'news' => [ |
| 61 | + 'label' => 'News', |
| 62 | + 'singular_label' => 'News Article', |
| 63 | + 'features' => ['categories', 'featured_image', 'excerpt'], |
| 64 | + 'category_types' => ['news-categories'], |
| 65 | + ], |
| 66 | + 'blog' => [ |
| 67 | + 'label' => 'Blog Posts', |
| 68 | + 'singular_label' => 'Blog Post', |
| 69 | + 'features' => ['categories', 'featured_image', 'excerpt', 'video-link'], |
| 70 | + 'category_types' => ['blog-categories'], |
| 71 | + ], |
| 72 | +], |
39 | 73 |
|
40 | | -If you discover any security related issues, please email [info@javaabu.com](mailto:info@javaabu.com) instead of using the issue tracker. |
| 74 | +'category_types' => [ |
| 75 | + 'news-categories' => [ |
| 76 | + 'label' => 'News Categories', |
| 77 | + 'singular_label' => 'News Category', |
| 78 | + 'hierarchical' => true, |
| 79 | + ], |
| 80 | +], |
| 81 | +``` |
41 | 82 |
|
42 | | -## Credits |
| 83 | +## Register Routes |
43 | 84 |
|
44 | | -- [Javaabu Pvt. Ltd.](https://github.com/javaabu) |
45 | | -- [Arushad Ahmed (@dash8x)](http://arushad.com) |
46 | | -- [FlameXode (@WovenCoast)](https://github.com/WovenCoast) |
47 | | -- [All Contributors](../../contributors) |
| 85 | +Add CMS routes to your `routes/web.php`: |
| 86 | + |
| 87 | +```php |
| 88 | +use Javaabu\Cms\Support\Routes; |
| 89 | + |
| 90 | +// Admin routes |
| 91 | +Routes::admin( |
| 92 | + prefix: 'admin', |
| 93 | + middleware: ['web', 'auth', 'verified'] |
| 94 | +); |
| 95 | + |
| 96 | +// Public routes |
| 97 | +Routes::web(); |
| 98 | + |
| 99 | +// Or register custom post type routes |
| 100 | +Routes::customPostType( |
| 101 | + postTypeSlug: 'news', |
| 102 | + prefix: 'news', |
| 103 | + middleware: ['web'] |
| 104 | +); |
| 105 | +``` |
| 106 | + |
| 107 | +## Usage |
| 108 | + |
| 109 | +### Creating Post Types |
| 110 | + |
| 111 | +Post types can be created via: |
| 112 | + |
| 113 | +1. **Database Seeder**: |
| 114 | +```php |
| 115 | +use Javaabu\Cms\Models\PostType; |
| 116 | + |
| 117 | +PostType::create([ |
| 118 | + 'name' => 'News', |
| 119 | + 'singular_name' => 'News Article', |
| 120 | + 'slug' => 'news', |
| 121 | + 'icon' => 'newspaper', |
| 122 | + 'features' => [ |
| 123 | + 'categories' => true, |
| 124 | + 'featured_image' => true, |
| 125 | + 'excerpt' => true, |
| 126 | + ], |
| 127 | +]); |
| 128 | +``` |
| 129 | + |
| 130 | +2. **Admin Panel**: Navigate to `/admin/post-types` after setup |
| 131 | + |
| 132 | +### Creating Posts |
| 133 | + |
| 134 | +```php |
| 135 | +use Javaabu\Cms\Models\Post; |
| 136 | +use Javaabu\Cms\Enums\PostStatus; |
| 137 | + |
| 138 | +$post = Post::create([ |
| 139 | + 'type' => 'news', |
| 140 | + 'title' => 'Breaking News', |
| 141 | + 'slug' => 'breaking-news', |
| 142 | + 'content' => '<p>Content here...</p>', |
| 143 | + 'excerpt' => 'Short description', |
| 144 | + 'status' => PostStatus::PUBLISHED->value, |
| 145 | + 'published_at' => now(), |
| 146 | +]); |
| 147 | + |
| 148 | +// Attach categories |
| 149 | +$post->categories()->attach($categoryIds); |
| 150 | +``` |
| 151 | + |
| 152 | +### Querying Posts |
| 153 | + |
| 154 | +```php |
| 155 | +use Javaabu\Cms\Models\Post; |
| 156 | + |
| 157 | +// Get published posts of a type |
| 158 | +$posts = Post::postType('news') |
| 159 | + ->published() |
| 160 | + ->ordered() |
| 161 | + ->paginate(15); |
| 162 | + |
| 163 | +// Search posts |
| 164 | +$posts = Post::postType('news') |
| 165 | + ->search('keyword') |
| 166 | + ->published() |
| 167 | + ->get(); |
| 168 | + |
| 169 | +// Get posts by year |
| 170 | +$posts = Post::postType('news') |
| 171 | + ->publishedByYear(2024) |
| 172 | + ->get(); |
| 173 | +``` |
| 174 | + |
| 175 | +### Working with Categories |
| 176 | + |
| 177 | +```php |
| 178 | +use Javaabu\Cms\Models\Category; |
| 179 | + |
| 180 | +// Get categories for select dropdown |
| 181 | +$categories = Category::categoryList($typeId); |
| 182 | + |
| 183 | +// Get nested categories |
| 184 | +$categories = Category::categoryType($typeId) |
| 185 | + ->defaultOrder() |
| 186 | + ->get() |
| 187 | + ->toTree(); |
| 188 | +``` |
| 189 | + |
| 190 | +## Available Post Type Features |
| 191 | + |
| 192 | +- `categories` - Category support |
| 193 | +- `featured_image` - Featured image |
| 194 | +- `excerpt` - Post excerpt |
| 195 | +- `documents` - Document attachments |
| 196 | +- `image_gallery` - Image gallery |
| 197 | +- `video_link` - Video embed URL |
| 198 | +- `document_number` - Document reference number |
| 199 | +- `expireable` - Expiry date |
| 200 | +- `format` - Post format (standard, video, gallery, etc.) |
| 201 | +- `page_style` - Custom page styling |
| 202 | +- `ref_no` - Reference number |
| 203 | +- `gazette_link` - Gazette document link |
| 204 | + |
| 205 | +## Permissions |
| 206 | + |
| 207 | +The package dynamically creates permissions for each Post Type and Category Type you create. Permissions are based on the slug of the type. |
| 208 | + |
| 209 | +### Post Type Permissions |
| 210 | + |
| 211 | +For each Post Type (e.g., 'news'), the following permissions are created: |
| 212 | +- `edit_{slug}` - Edit own posts (e.g., `edit_news`) |
| 213 | +- `edit_others_{slug}` - Edit all posts (e.g., `edit_others_news`) |
| 214 | +- `delete_{slug}` - Delete own posts |
| 215 | +- `delete_others_{slug}` - Delete all posts |
| 216 | +- `view_{slug}` - View own posts |
| 217 | +- `view_others_{slug}` - View all posts |
| 218 | +- `force_delete_{slug}` - Force delete own posts |
| 219 | +- `force_delete_others_{slug}` - Force delete all posts |
| 220 | +- `publish_{slug}` - Publish own posts |
| 221 | +- `publish_others_{slug}` - Publish all posts |
| 222 | +- `import_{slug}` - Import posts |
| 223 | + |
| 224 | +### Category Type Permissions |
| 225 | + |
| 226 | +For each Category Type (e.g., 'news-categories'), the following permissions are created: |
| 227 | +- `edit_{slug}` - Edit categories (e.g., `edit_news_categories`) |
| 228 | +- `delete_{slug}` - Delete categories |
| 229 | +- `view_{slug}` - View categories |
| 230 | +- `import_{slug}` - Import categories |
| 231 | + |
| 232 | +### Seeding Permissions |
| 233 | + |
| 234 | +Seed them using: |
| 235 | + |
| 236 | +```php |
| 237 | +use Javaabu\Cms\seeders\CmsPermissionsSeeder; |
| 238 | + |
| 239 | +CmsPermissionsSeeder::seedPermissions(); |
| 240 | +``` |
| 241 | + |
| 242 | +Call this after creating your Post Types and Category Types to generate the appropriate permissions. |
| 243 | + |
| 244 | +## Frontend Integration |
| 245 | + |
| 246 | +The package provides models and data - implement your own views: |
| 247 | + |
| 248 | +```blade |
| 249 | +{{-- resources/views/posts/index.blade.php --}} |
| 250 | +@foreach($posts as $post) |
| 251 | + <article> |
| 252 | + <h2>{{ $post->title }}</h2> |
| 253 | + <p>{{ $post->excerpt }}</p> |
| 254 | + <a href="{{ route('posts.show', [$post->type, $post->slug]) }}"> |
| 255 | + Read More |
| 256 | + </a> |
| 257 | + </article> |
| 258 | +@endforeach |
| 259 | +``` |
| 260 | + |
| 261 | +## Editor.js Integration |
| 262 | + |
| 263 | +Install the required npm packages: |
| 264 | + |
| 265 | +```bash |
| 266 | +npm install --save @editorjs/editorjs @editorjs/header @editorjs/list @editorjs/image @editorjs/quote @editorjs/table @editorjs/delimiter @editorjs/embed @editorjs/link @editorjs/raw @editorjs/simple-image @calumk/editorjs-columns |
| 267 | +``` |
| 268 | + |
| 269 | +Or copy dependencies from `package.json` in the package root. |
| 270 | + |
| 271 | +### Frontend Configuration |
| 272 | + |
| 273 | +You must also configure the `window.Laravel` object in your admin layout. See the [Installation and Setup Guide](docs/installation-and-setup.md#laravel-object-configuration) for details. |
| 274 | + |
| 275 | +## Testing |
| 276 | + |
| 277 | +```bash |
| 278 | +composer test |
| 279 | +``` |
| 280 | + |
| 281 | +## Documentation |
| 282 | + |
| 283 | +For detailed documentation, see the [docs](docs/) directory: |
| 284 | + |
| 285 | +- [Installation and Setup](docs/installation-and-setup.md) |
| 286 | +- [Requirements](docs/requirements.md) |
| 287 | +- [Basic Usage](docs/basic-usage/) |
| 288 | + |
| 289 | +## Contributing |
| 290 | + |
| 291 | +Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details. |
| 292 | + |
| 293 | +## Security |
| 294 | + |
| 295 | +If you discover any security-related issues, please email security@javaabu.com instead of using the issue tracker. |
48 | 296 |
|
49 | 297 | ## License |
50 | 298 |
|
51 | 299 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 300 | + |
| 301 | +## Credits |
| 302 | + |
| 303 | +- [Javaabu](https://javaabu.com) |
| 304 | +- [All Contributors](../../contributors) |
0 commit comments