Skip to content

Instantly share code, notes, and snippets.

@iboved
Last active May 27, 2019 08:17
Show Gist options
  • Save iboved/e38bb9ffe4e361c1d1f60fa5639ffba8 to your computer and use it in GitHub Desktop.
Save iboved/e38bb9ffe4e361c1d1f60fa5639ffba8 to your computer and use it in GitHub Desktop.
Post model, Posts controller, fields.yaml, migration file
<?php namespace Acme\Demo\Updates;
use Schema;
use October\Rain\Database\Schema\Blueprint;
use October\Rain\Database\Updates\Migration;
class CreatePostsTable extends Migration
{
public function up()
{
Schema::create('acme_demo_posts', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->text('content')->nullable();
});
}
public function down()
{
Schema::dropIfExists('acme_demo_posts');
}
}
# ===================================
# Form Field Definitions
# ===================================
fields:
content:
label: Content
type: repeater
prompt: Add Content Item
form:
fields:
blocks:
label: Blocks
type: repeater
prompt: Add Block Item
form:
fields:
title:
label: Description
type: textarea
<?php namespace Acme\Demo\Models;
use Model;
/**
* Post Model
*/
class Post extends Model
{
/**
* @var string The database table used by the model.
*/
public $table = 'acme_demo_posts';
public $timestamps = false;
/**
* @var array Attribute names to encode and decode using JSON.
*/
protected $jsonable = [
'content',
];
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array Fillable fields
*/
protected $fillable = [];
/**
* @var array Relations
*/
public $hasOne = [];
public $hasMany = [];
public $belongsTo = [];
public $belongsToMany = [];
public $morphTo = [];
public $morphOne = [];
public $morphMany = [];
public $attachOne = [];
public $attachMany = [];
}
<?php namespace Acme\Demo\Controllers;
use BackendMenu;
use Backend\Classes\Controller;
/**
* Posts Back-end Controller
*/
class Posts extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController'
];
public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public function __construct()
{
parent::__construct();
BackendMenu::setContext('Acme.Demo', 'demo', 'posts');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment