Coder Social home page Coder Social logo

statamic / custom-publish-forms-eloquent Goto Github PK

View Code? Open in Web Editor NEW
11.0 6.0 4.0 4.57 MB

An example of using Custom Publish forms powered by Eloquent.

Home Page: https://statamic.com/blog/custom-publish-forms

PHP 22.30% HTML 38.47% CSS 36.38% JavaScript 2.85%
statamic statamic-v2 statamic-addon database eloquent laravel

custom-publish-forms-eloquent's Introduction

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.

custom-publish-forms-eloquent's People

Contributors

jackmcdade avatar jasonvarga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.