Skip to content
An example of using Custom Publish forms powered by Eloquent.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
local statamic May 31, 2018
site
.gitignore Ignore statamic directory Jun 11, 2018
README.md Readme Jun 11, 2018
index.php
phpunit.xml
please statamic May 31, 2018
robots.txt
sample.env
sample.htaccess
sample.nginx.conf statamic May 31, 2018
sample.web.config statamic May 31, 2018

README.md

Custom Publish Forms + Eloquent

An example of using Custom Publish forms powered by Eloquent models in a Statamic addon.

Set up the database

Create a database and add the credentials to your .env file.

DB_HOST=localhost
DB_DATABASE=statamic-eloquent
DB_USERNAME=root
DB_PASSWORD=

You would then create your migrations, like any Laravel install. We have included one in this repo.

php please migrate

Sidebar Navigation

We have a Listener file that takes care of adding an item to the navigation. Click the Products item in the sidebar to view the listing.

Fieldset

When creating or editing a product, the publish component will be rendered according to the provided product fieldset.

To add more fields, you should create a migration (or update the original one) to add the columns to the table, and also add fields to the fieldset so they are rendered on the publish page.

Validation

This repo assumes you want to use validation defined as in the fieldset.

If you want, you may bypass that entirely and write your own validator. Be aware that the fields will be submitted in a nested fields array. You will need to do something like this:

Validator::make($request->all(), [
    'fields.title' => 'required'
]);

Front-end

The /products route is a page that loads a template containing a simple custom tag.

The /products/{slug} route is a wildcard route that loads a template with another simple custom tag.

You can’t perform that action at this time.