feat(11.1-05): add the walkthrough's admin controller, publish command and published_at migration
- make:admin-controller, make:command and make:migration output, finished: the Posts controller serves models.Post behind acme.blog.access_posts, WinterCMS-style form and list YAML embedded through pact.AdminAssets, blog:publish sets published_at by slug with a bound parameter - the posts route lists published posts only, newest first - Docker tests migrate an ICU pl-PL database, roll back published_at, serve the route and run blog:publish with a published and an opened database - the page gains the admin controller, console command and added-column sections
This commit is contained in:
@@ -11,12 +11,13 @@ import (
|
||||
// Post is a blog post, the Go form of the WinterCMS Acme\Blog\Models\Post
|
||||
// model.
|
||||
type Post struct {
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
Title string `gorm:"column:title"`
|
||||
Slug string `gorm:"column:slug"`
|
||||
Body string `gorm:"column:body"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
Title string `gorm:"column:title"`
|
||||
Slug string `gorm:"column:slug"`
|
||||
Body string `gorm:"column:body"`
|
||||
PublishedAt *time.Time `gorm:"column:published_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
}
|
||||
|
||||
// TableName keeps the WinterCMS table name.
|
||||
@@ -26,6 +27,15 @@ func (Post) TableName() string { return "acme_blog_posts" }
|
||||
// set from a request.
|
||||
func (Post) Fillable() []string { return []string{"title", "slug", "body"} }
|
||||
|
||||
// Rules is the Go form of $rules. The admin API checks them with
|
||||
// lagoon.Validate on every save; unique ignores the post being updated.
|
||||
func (Post) Rules() map[string]string {
|
||||
return map[string]string{
|
||||
"title": "required|max:255",
|
||||
"slug": "required|max:255|unique:acme_blog_posts",
|
||||
}
|
||||
}
|
||||
|
||||
// NewPost is the Go form of Post::make($input): it copies only the fillable
|
||||
// keys of input onto a new post and drops the rest, such as id.
|
||||
func NewPost(input map[string]any) (*Post, error) {
|
||||
|
||||
Reference in New Issue
Block a user