PHPackages                             niku-solutions/cms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. niku-solutions/cms

ActiveLibrary

niku-solutions/cms
==================

A codeable and flexible custom post type manager for Laravel with custom fields. Extendable and as dynamic as you wish.

3.2.80(8y ago)364532[1 issues](https://github.com/nickkuijpers/laravel-custom-post-manager/issues)1MITPHPPHP ^7.0|^7.1

Since Sep 29Pushed 8y ago4 watchersCompare

[ Source](https://github.com/nickkuijpers/laravel-custom-post-manager)[ Packagist](https://packagist.org/packages/niku-solutions/cms)[ RSS](/packages/niku-solutions-cms/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (4)Versions (116)Used By (1)

Laravel Post Manager
====================

[](#laravel-post-manager)

[![Latest Stable Version](https://camo.githubusercontent.com/1dd1769694171d8d2b8c50d3a66083f833c4d45b81de21ef9cb6c3e90015b037/68747470733a2f2f706f7365722e707567782e6f72672f6e696b752d736f6c7574696f6e732f636d732f762f737461626c65)](https://packagist.org/packages/niku-solutions/cms)[![Latest Unstable Version](https://camo.githubusercontent.com/b88384539bf65b686f4f9640da1e9fa61edd03fce76e06dadcc7995086541dee/68747470733a2f2f706f7365722e707567782e6f72672f6e696b752d736f6c7574696f6e732f636d732f762f756e737461626c65)](https://packagist.org/packages/niku-solutions/cms)[![License](https://camo.githubusercontent.com/bbf098712a0d0c03176b9fb5c938218563687f73b1011bd267115e554a9324fa/68747470733a2f2f706f7365722e707567782e6f72672f6e696b752d736f6c7574696f6e732f636d732f6c6963656e7365)](https://packagist.org/packages/niku-solutions/cms)[![Monthly Downloads](https://camo.githubusercontent.com/83d9152fba031d701ad90a1b0becdea7d8bea1a5b2b715a5563bacb4746ad1c0/68747470733a2f2f706f7365722e707567782e6f72672f6e696b752d736f6c7574696f6e732f636d732f642f6d6f6e74686c79)](https://packagist.org/packages/niku-solutions/cms)

A API based codeable post manager for Laravel with custom fields. Extendable as you wish. Based on the API request, you will receive the post type configurations in a way where you can build your front-end with. We will take care of the CRUD functionality with support of taxonomies, media management and post meta.

We use our package internally in our projects to remove the need of basic post management. We are now able to setup advanced dashboard functionality for all type of post data like Pages, Posts, Products and whatever post type or category you require. You can add or remove custom fields in no time with no need to touch the database as the package does that automatically for you and save the data and shows it to you when displaying the editting form.

> We are working on a decoupled front-end package in Vue.js and Axios which makes it possible to interact with the API in your Laravel project or Single Page Application.

#### Features

[](#features)

- Custom post types
- Configuration pages
- Taxonomies like categories
- Media manager with upload functionality and management
- Repeating custom field groups
- Custom fields
- Validation rules for custom fields
- Conditional custom fields based on template selection
- Easy default user authentication based on if a user is logged in
- Possibility to let users only view their own posts
- Menu management support, you will need our front-end package for that.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require niku-solutions/cms

```

Register the following class into the 'providers' array in your config/app.php

```
Niku\Cms\CmsServiceProvider::class,
```

Register the following middleware to whitelist your post types and config groups in the route files. You dont have to do anything further with this as we use this in our provider to secure the api routes of the post manager.

```
use Niku\Cms\Http\Middlewares\WhitelistPostTypesMiddleware;
use Niku\Cms\Http\Middlewares\WhitelistConfigGroupsMiddleware;

protected $routeMiddleware = [
	...
    'posttypes' => WhitelistPostTypesMiddleware::class,
    'groups' => WhitelistConfigGroupsMiddleware::class,
	...
];
```

You need to run the following artisan command to publish the required config file to register your post types.

```
php artisan vendor:publish --tag=niku-config

```

If you run the following vendor publish, you will receive a example set of post types to use

```
php artisan vendor:publish --tag=niku-posttypes

```

Migrate the database tables by running:

```
php artisan migrate

```

### Usage

[](#usage)

Before you are able to use the post types, you need to whitelist and setup the required custom fields and templates in the config/niku-cms.php file.

```
return [
    'post_types' => [

        // Default
        'attachment' => App\Cms\PostTypes\Attachment::class,

        // CMS
        'page' => App\Cms\PostTypes\Pages::class,
        'posts' => App\Cms\PostTypes\Pages::class,
        'posts-category' => App\Cms\PostTypes\PostsCategory::class,

    ],

    'config_types' => [

        // Registering the single config page
        'defaultsettings' => App\Cms\ConfigTypes\DefaultSettings::class,

    ];
```

You can register the routes by pasting the following method in your route file. You can add middlewares like you would normally do to secure the routes with authentication etc. The post\_type in the registed routes are variable but secured by a parameter in the method, so by default no api requests are enabled.

To enable the API routes, you need to register the names of the post types you would like to use as you see in the 'register\_post\_types' array key below. When registering a post type, you fill in the name of the array key in the config/niku-cms.php file. For more information about the config, read on.

If you for example have 2 user roles which have to communicate to the same post type but require different permissions, you can create 2 config files where the normal user account can only view their own posts, and the superadmin can view all of the users their posts. You do that by naming the array key of the config/niku-cms.php unique and creating 2 config files where the '$identifier' is pointed to the same 'post\_type'.

```
Niku\Cms\Cms::postTypeRoutes([
	'register_post_types' => [
		'posts',
		'superadminposts',
	],
]);

// Registering the routes for config pages
Niku\Cms\Cms::postTypeRoutes([
	'register_groups' => [
		'defaultsettings',
	],
]);
```

For each post type registered, you can set up default data and custom fields. You can add validations to the validation array key of the custom field you insert. All Laravel validation rules will be supported as it will only pass it thru to the validator class.

```
namespace App\Cms\PostTypes;

use Niku\Cms\Http\NikuPosts;

class Pages extends NikuPosts
{
    // The label of the custom post type
    public $label = 'Pages';

    // Custom post type identifer
	public $identifier = 'page';

    // Users can only view their own posts when this is set to true
    public $userCanOnlySeeHisOwnPosts = false;

    public $config = [

    ];

    // Setting up the template structure
    public $templates = [
        'default' => [
            'customFields' => [
                'post_content' => [
                    'component' => 'niku-cms-text-customfield',
                    'label' => 'Text',
                    'value' => '',
                    'validation' => 'required',
                ],
                'author' => [
                    'component' => 'niku-cms-text-customfield',
                    'label' => 'Author',
                    'validation' => 'required',
                ],
                // more custom fields
            ],
        ],
    ];

}
```

Do you want to change the custom fields displayed based on the template? You can add multiple views which are selectable in the frontend for the end user and change the visible custom fields.

```
public $templates = [
    'default' => [
        'label' => 'Default page',
        'template' => 'default',
        'customFields' => [
            'text' => [
                'component' => 'niku-cms-text-customfield',
                'label' => 'Text',
                'value' => '',
                'validation' => 'required',
            ]
        ]
    ],
    'sidebar' => [
        'label' => 'Sidebar layout',
        'template' => 'sidebar-layout',
        'customFields' => [
            'text' => [
                'component' => 'niku-cms-text-customfield',
                'label' => 'Text',
                'value' => '',
                'validation' => 'required',
            ]
        ]
    ],
];
```

#### Blog

[](#blog)

If you want a blog like method, you can do the following.

Enable the following type in your routes/web.php.

```
Route::get('blog', 'BlogController@blog');
Route::get('blog/{slug}', 'BlogController@singleBlog');
```

Next you enable the required methods in the controller.

```
public function blog()
{
    $posts = Posts::where([
        ['status', '=', '1'],
        ['post_type', '=', 'post']
    ])->with('postmeta')->get();
    return view('static.blog', compact('posts'));
}
```

And then in your view, you do the following. This syntax will be recreated in the future to make it more fluent but for now it works.

```
@foreach($posts as $post)

        @if(!empty($post->getMeta('image')))
