| title | Installation & Setup |
|---|---|
| sidebar_position | 1.2 |
This guide will walk you through installing and setting up the Javaabu CMS package in your Laravel application.
Install the package via composer:
composer require javaabu/cmsThe easiest way to set up the CMS is using the setup command:
php artisan cms:setupThis command will:
- Publish the configuration file
- Publish and run migrations
- Optionally install default post types and categories
- Seed CMS permissions
- Display next steps
# Install with default post types and categories
php artisan cms:setup --with-defaults
# Skip migrations
php artisan cms:setup --skip-migrations
# Skip permission seeding
php artisan cms:setup --skip-permissions
# Force in production
php artisan cms:setup --force
# Combine options
php artisan cms:setup --with-defaults --forceWhen using the --with-defaults option (or when prompted during setup), the following will be installed:
Post Types:
- News
- Blog Posts
- Downloads
- Announcements
- Publications
- Jobs
- Galleries
- Tenders
- Reports
- Pages
Category Types:
- News Categories
- Blog Categories
- Download Categories
- Announcement Categories
- Publication Categories
- Job Categories
- Gallery Categories
- Tender Categories
- Report Categories
Sample Categories:
- News: General, Press Releases
- Blog: Technology, Business
- Jobs: Full Time, Part Time, Intern
:::tip
You can customize these defaults in config/cms.php under default_category_types, default_post_types, and default_categories before running the setup command.
:::
Add CMS routes to your routes/web.php:
use Javaabu\Cms\Support\Routes;
// Admin routes (protected by auth middleware)
Routes::admin(
prefix: 'admin',
middleware: ['web', 'auth', 'verified']
);
// Public routes (for displaying posts)
Routes::web(
prefix: null, // or 'blog', 'news', etc.
middleware: ['web']
);You can customize routes per post type:
use Javaabu\Cms\Support\Routes;
// Register routes for a specific post type
Routes::customPostType(
postTypeSlug: 'news',
prefix: 'news',
middleware: ['web'],
controller: '\App\Http\Controllers\NewsController' // Optional custom controller
);Add CMS routes to your admin routes file (typically routes/admin.php):
use Javaabu\Cms\Http\Controllers\Admin\MediaController;
// Media routes
Route::match(['PUT', 'PATCH'], 'media', [MediaController::class, 'bulk'])->name('media.bulk');
Route::get('media/picker', [MediaController::class, 'picker'])->name('media.picker');
Route::resource('media', MediaController::class, [
'parameters' => [
'media' => 'media',
],
]);The config file is automatically published during setup, but you can republish it:
php artisan vendor:publish --tag=cms-configThe configuration file (config/cms.php) contains:
<?php
return [
/*
|--------------------------------------------------------------------------
| Post Types
|--------------------------------------------------------------------------
*/
'post_types' => [
'news' => [
'label' => 'News',
'singular_label' => 'News Article',
'features' => ['categories', 'featured_image', 'excerpt'],
'category_types' => ['news-categories'],
],
],
/*
|--------------------------------------------------------------------------
| Category Types
|--------------------------------------------------------------------------
*/
'category_types' => [
'news-categories' => [
'label' => 'News Categories',
'singular_label' => 'News Category',
'hierarchical' => true,
],
],
/*
|--------------------------------------------------------------------------
| Default Post Type Features
|--------------------------------------------------------------------------
*/
'default_features' => [
'title',
'content',
'excerpt',
'featured_image',
'categories',
'publish_date',
'status',
'slug',
],
/*
|--------------------------------------------------------------------------
| Media Settings
|--------------------------------------------------------------------------
*/
'media' => [
'featured_image_sizes' => [
'thumb' => [300, 300],
'medium' => [600, 400],
'large' => [1200, 800],
],
],
/*
|--------------------------------------------------------------------------
| Pagination Settings
|--------------------------------------------------------------------------
*/
'pagination' => [
'per_page' => 15,
],
];If you skipped migrations during setup, run them manually:
php artisan migrateTo customize migrations, publish them first:
php artisan vendor:publish --tag=cms-migrationsThis creates the following tables:
category_typescategoriespost_typespostscategory_model(pivot table)
If you skipped permissions during setup, seed them manually:
use Javaabu\Cms\seeders\CmsPermissionsSeeder;
CmsPermissionsSeeder::seedPermissions();Or add to your DatabaseSeeder:
public function run()
{
// Other seeders...
\Javaabu\Cms\seeders\CmsPermissionsSeeder::seedPermissions();
}The package dynamically creates permissions for each Post Type and Category Type you create. Permissions are based on the slug of the type.
Post Type Permissions (11 per type):
For each Post Type (e.g., 'news'), the following permissions are created:
edit_{slug}- Edit own posts (e.g.,edit_news)edit_others_{slug}- Edit all postsdelete_{slug}- Delete own postsdelete_others_{slug}- Delete all postsview_{slug}- View own postsview_others_{slug}- View all postsforce_delete_{slug}- Force delete own postsforce_delete_others_{slug}- Force delete all postspublish_{slug}- Publish own postspublish_others_{slug}- Publish all postsimport_{slug}- Import posts
Category Type Permissions (4 per type):
For each Category Type (e.g., 'news-categories'), the following permissions are created:
edit_{slug}- Edit categories (e.g.,edit_news_categories)delete_{slug}- Delete categoriesview_{slug}- View categoriesimport_{slug}- Import categories
:::tip
Call CmsPermissionsSeeder::seedPermissions() after creating your Post Types and Category Types to generate the appropriate permissions.
:::
If using Editor.js for content editing:
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-columnsOr copy from package.json:
{
"dependencies": {
"@calumk/editorjs-columns": "^0.3.2",
"@editorjs/delimiter": "^1.4.2",
"@editorjs/editorjs": "^2.29.1",
"@editorjs/embed": "^2.7.4",
"@editorjs/header": "^2.6.0",
"@editorjs/image": "^2.6.0",
"@editorjs/link": "^2.3.1",
"@editorjs/list": "^1.6.1",
"@editorjs/quote": "^2.4.0",
"@editorjs/raw": "^2.2.0",
"@editorjs/simple-image": "^1.4.0",
"@editorjs/table": "^1.3.0"
}
}To enable correct functionality for the Media Picker and other CMS features, add the following script block to your admin layout's <head>:
<script>
window.Laravel = <?php echo json_encode([
'csrfToken' => csrf_token(),
'mediaPicker' => translate_route('admin.media.picker'),
'locale' => app()->getLocale(),
'admin_domain' => url(''),
'public_domain' => config('app.url')
]); ?>
</script>To include the Media Library styles, import the SASS file in your admin.scss:
@import 'inc/media-library';
@import 'inc/fileinput-overrides';After installation, verify everything is working:
- Check routes:
php artisan route:list | grep cms - Check migrations: Verify tables exist in database
- Access admin panel: Visit
/admin/category-types(requires authentication) - Check permissions: Verify permissions exist in your permissions table