rikh's avatar
Level 3

Integrate a CMS into Laravel 5

We have a complex site created using L5 and would like to add a CMS to manage the content on a few of public pages (think home page, about us, a couple of feature and information pages etc).

Can anyone suggest a good CMS that can be added as a package to manage some of the site. I know there are a million options if I want a 100% content managed site, like wordpress, Perch, October etc. I'm looking at adding a bit of content managed material to an existing site and don't want the CMS to dictate how everything else should work.

0 likes
13 replies
michaelpittino's avatar

I don't know any packages which would do what you want. But I'd suggest to write such a package by yourself.

RemiC's avatar

The closest fit I can think of is FrozenNode/Laravel-Administrator package.

davidrushton's avatar

Not sure if this helps, but we had a specific requirement to use Wordpress for the CMS but Laravel to handle payments and some other custom functionality.

The approach we use is a rather simple one - a set of reserved URLs that Laravel hijacks and then the rest are continued on to Wordpress.

Our public/index.php looks something like this

<?php

if ( file_exists(__DIR__.'/wp/index.php') ) {

    $segments = ( isset($_SERVER['REQUEST_URI']) ? explode('/', trim($_SERVER['REQUEST_URI'],'/')) : array('/') );

    $urls = ['api','shop','admin','donate','_debugbar'];
    
    if ( ! in_array($segments[0], $urls) ) {
        require_once __DIR__.'/wp/vendor/autoload.php';
        require_once __DIR__.'/wp/index.php';
        exit;
    }

}

// Laravel bootstrap stuff here

Then, we put all the Wordpress code in public/wp a la https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory (we also use https://roots.io which is why Wordpress includes a composer vendor autoload file).

We also wanted to share the Wordpress theme header and footer on our Laravel site, so we :

  1. Wrote the following functions into our functions.php:
<?php

function site_primary_navigation()
{
    $cache = new \Illuminate\Cache\FileStore(new \Illuminate\Filesystem\Filesystem(), ABSPATH.'/cache');

    $menu = wp_nav_menu(['theme_location' => 'primary_navigation', 'menu_class' => 'nav navbar-nav navbar-right', 'echo' => false]);

    if ( ! $cache->get('wp_nav') ) {
        $cache->put('wp_primary_nav', str_replace('class="active', 'class="', $menu), 1440);
    }

    return $menu;
}

function site_primary_footer()
{
    $cache = new \Illuminate\Cache\FileStore(new \Illuminate\Filesystem\Filesystem(), ABSPATH.'/cache');

    ob_start();
    get_template_part('templates/footer', 'primary');
    $footer = ob_get_contents();
    ob_end_clean();

    if ( ! $cache->get('wp_footer') ) {
        $cache->put('wp_footer', $footer, 1440);
    }

    return $footer;
}
  1. Used those functions in Wordpress header.php and footer.php

  2. In Laravel blade partials / layouts we did:

<?php
    $cache = new \Illuminate\Cache\FileStore(new \Illuminate\Filesystem\Filesystem(), Config::get('wordpress.cache_path'));
    echo $cache->get('wp_primary_nav');
?>

Where cache_path is set up in a wordpress.php config file with the path to our Wordpress root / cache folder

David.

10 likes
jkoech's avatar

I haven't used a package before but I think the best best option would be for you to write your own or get someone to assist. It's not that difficult and won't take much of your time.

RemiC's avatar

@davidrushton : I would preferly not be using a monolitic CMS alongside Laravel unless its a mandatory requirement. The cost of maintaining two systems would probably be higher than coding a quick custom system to manage a few pages.

I assume sometimes it may works ok, but that moslty depends on the type of the project, as most of the time you'd need to have both CMS content and Application related stuff on a same page.

davidrushton's avatar

@RemiC Sure, yeah - it completely depends on the project. In this case the client was specifically moving from a Wordpress managed site and wanted to retain that for the CMS while we built a bespoke payment system and backend. In other cases where the development cost is too high to replicate something like WP, it might also make sense, however as you said if you want to tightly integrate the frontend or authentication etc then it becomes a headache.

nWidart's avatar

You can also try AsgardCms which is a modular and multilingual cms built on laravel 5. It's very easy to develop larger applications using this.

cmosguy's avatar

Hi All,

I went ahead and blogged about this today. I figured out how to combine some of these ideas into an easy to read tutorial.

I got into detail how to use Laravel 5.1 and Wordpress (using the Bedrock install from roots.io) in parallel. The key is to modify the public/index.php to filter which routes you want controlled by Laravel. Check it out: http://bit.ly/1KxQcAT I hope it helps!

3KyNoX's avatar

Hello,

Following multiple examples here :

http://blog.grossi.io/2014/working-with-laravel-4-and-wordpress-together/

http://adampatterson.ca/blog/2015/06/using-wordpress-with-lumen/

http://nehalist.io/integrating-laravel-into-wordpress/

http://adamklein.io/blog/2015/10/13/laravel-5-1-and-bedrock-wordpress/

... from WP Backend, how can I manage new pages created from WP Admin for example and get content of newly created page inside Laravel ?

2 likes

Please or to participate in this conversation.