Close "PHP level" integration with Laravel?

Hi all,

Hope you’re well!

I’m just wondering how you, personally, might approach integrating Kirby with an existing Laravel application at “the PHP level” (i.e. without using the REST API) - if this is even possible.

In an ideal world, Laravel would handle the routing, authentication, presentation, and “framework” stuff and Kirby would handle the content - almost in a Statamic-esque way. I would use Statamic but I prefer the way that Kirby handles files and content, and I like Kirby’s API.

To give you a concrete example of what I’m asking, an extremely basic example would be:

  • A user visits /contact which is handled by a Laravel controller
  • The Laravel controller calls page('contact') and Kirby returns the relevant object
  • The object is passed to a Blade template

Alternatively: from within a Laravel controller site()->index() could be called to return a collection of all pages.

I hope that you get the gist. I would like to use the content management API of Kirby within Laravel.

My instinct is that this would be quite finicky to do, would be rife with instability, and is not an idea worth pursuing. I just wanted to get a quick opinion from the Kirby Experts™ before I wrote this off completely.

Thank you for your input in advance! Any opinions are much appreciated.

Theoretically, you could use Kirby as a dependency, like we do in this external migrate script example:

With that, you have full access to Kirby’s API.

But since Kirby uses its own router, ways to pass stuff around etc., I have no idea if this would work out at all besides such basic stuff.

Thanks for your reply, Sonja!

This is what I tried initially, but I quickly ran into global helper function conflicts and such. I (messily) instantiated Kirby within Laravel, passed the request data over, and modified some Kirby files to allow it to grab the correct instance from Laravel’s dependency container.

Although I could ‘fight fires’ as they arise, I sense going down this route would result in a fragile application.

I think this might be a REST-API-or-nothing scenario!

Thanks again.