sinevia/laravel-cms

Content Management System for Laravel

Installs: 1 230

Dependents: 0

Suggesters: 0

Security: 0

Stars: 20

Watchers: 5

Forks: 7

Open Issues: 2

Language:Blade

v2.37.0 2023-11-14 06:29 UTC

README

Total Downloads Latest Stable Version Latest Unstable Version License Monthly Downloads Daily Downloads composer.lock

A "plug-and-play" content managing system (CMS) for Laravel that does its job and stays out of your way.

Introduction

All of the existing Laravel CMS (OctoberCms, AsgardCms, PyroCms, etc) require a full installations from scratch. Its impossible to just add them to an exiting Laravel application, and even when added feel like you don't get what you hoped for.

This package allows to add a content management system as a package dependency in your composer file, which can be easily updated or removed as required to ANY Laravel app. It is fully self contained, and does not require any additional packages or dependencies. Removal is also a breeze just remove from your composer file.

Features

  • Templates (aka master layouts)
  • Pages (web pages)
  • Blocks (reusable cutom pieces of code -- headers, footers)
  • Widgets (dynamic reusable pre-defined components)

Installation (est. 5-10 mins)

  • Install required library
composer require lesichkovm/laravel-advanced-route
composer require lesichkovm/laravel-advanced-model
  • Install the CMS
composer require sinevia/laravel-cms
php artisan migrate
php artisan vendor:publish --tag=config
// If you want the migrations, usually not needed
php artisan vendor:publish --tag=migrations
// If you want the views, usually not  needed
php artisan vendor:publish --tag=views

Word of warning. Do use a stable package, as "dev-master" is a work in progress.

Uninstall (est. 5 mins)##

Removal of the package is a breeze:

composer remove sinevia/laravel-cms

Optionally, delete the CMS tables (all which start with the snv_cms_ prefix)

Configuration

After running the vendor:publish command, the CMS settings will be published in the /config/cms.php config file. Check these out, and modify according to your taste

Route Settings

  1. CMS Endpoint (public, catch all)
\Route::group(['prefix' => '/'], function () {
    // will match only one level deep (not recommended)
    \Route::any('/{path?}', '\Sinevia\Cms\Http\Controllers\CmsController@anyPageView');
    
    // or use with regex expression to match any level
    \Route::any('/{path?}', '\Sinevia\Cms\Http\Controllers\CmsController@anyPageView')
        ->where('path', '([a-zA-z0-9\/\-]++)');
        
    // or use with simpler regex expression to match any level
    \Route::any('/{path?}', '\Sinevia\Cms\Http\Controllers\CmsController@anyPageView')
        ->where('path', '.+');

    // or if you prefer using the class path (recommended)
    \Route::any('/{path?}', [\Sinevia\Cms\Http\Controllers\CmsController::class, 'anyPageView'])
        ->where('path', '.+');
});
  1. Admin endpoint (private, protect with middleware)
\Route::group(['prefix' => '/admin'], function () {
    \Route::group(['middleware'=>'adminonly'], function(){
        \AdvancedRoute::controller('/cms', '\Sinevia\Cms\Http\Controllers\CmsController');

        // or if your prefer using class path (recommended)
        \AdvancedRoute::controller('/cms', \Sinevia\Cms\Http\Controllers\CmsController::class);
    });
});

Templates

The templates are layouts, that can be used to display the pages in a uniform fashion. You may have multiple templates which is useful if you want to have different "look and feel" for different sections of your website.

Pages

The pages are the content which displays when you visit a specified URL. Each page may have an optional parent template, which can specify common elements (i.e. style sheets, scripts, etc) for all pages sharing the template.

Blocks

The blocks are small content snippets which can be embedded into pages and templates. Useful if you want to use on multiple pages, or to make pages more lightweight.

To embed in page or template use a shortcode like this: [[BLOCK_20180509052702261348]]

Widgets

The widgets are predefined dynamic modules which can be embedded into pages and templates (i.e. Google Maps, Contact Forms, etc). Depending on the action they perform, these may or may not have optional or requred parameters. Each widget files reside in its own directory.

To embed in page or template use a shortcode like this: [[WIDGET_20180509052702261348]]

More info: https://github.com/Sinevia/laravel-cms/wiki/Widgets

Human Friendly Aliases

The following shortcuts can be used to create human friendly page aliases, that can be used for pages with dynamic content

Shortcut Regex
:any ([^/]+)
:num ([0-9]+)
:all (.*)
:string ([a-zA-Z]+)
:number ([0-9]+)
:numeric ([0-9-.]+)
:alpha' ([a-zA-Z0-9-_]+)

Example page alias: /article/:num/:string

To retrieve back you may use the following snippet

preg_match('#^/article/([0-9]+)/([a-zA-Z]+)/([a-zA-Z]+)$#', '/' . $uri, $matched);
$articleId = $matched[1] ?? "";

Quick Snippets

  1. Advanced usage. Use the CMS templates to wrap around custom code with blade templates:
// A small helper function to place HTML in the CMS template
function viewInTemplate($pageTitle, $pageContent) {
    $template = \Sinevia\Cms\Models\Template::find('20180126000128528925');

    return $template->render('en', [
                'page_title' => $pageTitle,
                'page_content' => $pageContent,
    ]);
}

// Then you may use from your controller, for instance to show a login form in
$html = view('guest/auth/login', get_defined_vars())->render();
return viewInTemplate('Login', $pageContent)

Screenshots

1. Page Manager

Alt text

2. Create New Page

Alt text

3. Edit Page. Content View

Alt text

4. Edit Page. SEO View

Alt text

5. Speed Test (before additional speed improvements)

Alt text

Changelog

2021.07.05 - Added support for Bootstrap 5

Alternatives

  • LavaLite - requires full project from scratch, cannot be embedded in existing project as package
  • OctoberCms - requires full project from scratch, cannot be embedded in existing project as package
  • TypiCms - requires full project from scratch, cannot be embedded in existing project as package
  • PyroCMS - requires full project from scratch, cannot be embedded in existing project as package
  • Laravel8SimpleCms - requires full project from scratch, cannot be embedded in existing project as package
  • Winter - requires full project from scratch, cannot be embedded in existing project as package
  • GraphiteInc CMS - Archived
  • Twil