Overview
There are many reasons why you might want to install Statamic into an existing Laravel application. You could use Statamic to:
- handle all the marketing and "logged out" content for a SaaS app
- add an easy-to-manage blog the whole team can update
- manage existing data kinda like Laravel Nova (yes, you can do that),
- run as a headless CMS and provide a REST API to your data
- be a special comfort package for those tough projects even when you don't need it
If you're starting a brand new project, it's much easier to use the standard Statamic installation method.
You'll get a bunch of things automatically set up for you, like a pages collection, views, etc. If you install Statamic into Laravel, you're going to have to do those things manually.
Supported Versions of Laravel
Laravel 10 & Laravel 11 are supported with Statamic 5. If you need Laravel 9 support, you can still use Statamic 4.x.
Install Statamic
There are 3 steps to follow to install Statamic into your Laravel app.
-
Run
php artisan config:clear
to make sure your config isn't cached. -
In
composer.json
, add the following items:"scripts": {"pre-update-cmd": ["Statamic\\Console\\Composer\\Scripts::preUpdateCmd"],"post-autoload-dump": ["Illuminate\\Foundation\\ComposerScripts::postAutoloadDump","@php artisan package:discover --ansi","@php artisan statamic:install --ansi"],} -
Install
statamic/cms
with Composer.composer require statamic/cms --with-dependencies -
Depending on how you set up users in your app, you might need to run a command to publish Statamic's auth migrations.
php please auth:migration
Adding Content
When you install Statamic into Laravel this way, no content or views are included.
You'll probably want to create a collection and some entries, as well as views and a layout in order to see things appear on the front-end of your site.
Pages
A common "catch-all" content scenario is to create a Pages collection which allows you to create a home page as well as any other pages in a tree structure. You get this when you install Statamic from scratch, but it's easy to set up yourself.
The easiest way is to copy the pages.yaml
file and the pages
directory from the statamic/statamic
repository.
Or, if you wanted to do it through the Control Panel:
- Create a collection named
pages
.- Set the route to
{parent_uri}/{slug}
- Enable the "Orderable" toggle
- Enabled the "Expect a root page" toggle
- Set the route to
- Create an entry. The first one will be your home page.
Views
Statamic routed URLs will expect views named default
and layout
. You will need to add those manually too.
Read more about how Statamic views and layouts work
Database
When you install Statamic into an existing Laravel application, content and users will be stored as flat files.
If you'd prefer to store these in the database, please follow these guides:
New Statamic Directories
After Statamic is installed, you'll have 3 new directories in your project:
-
content/
, -
resources/users/
-
config/statamic/
Statamic relies on a "catch-all" wildcard route to handle its URLs. Any explicitly defined routes in your application will take precedence over those handled by Statamic. Be sure that you don't have your own catch-all route or else nothing will ever be passed off to Statamic.