diff --git a/components/Categories.php b/components/Categories.php index 112e3c7..cc74a8f 100644 --- a/components/Categories.php +++ b/components/Categories.php @@ -74,7 +74,7 @@ public function prepareVars() public function listCategories() { - $categories = ShopCategory::all(); + $categories = ShopCategory::orderBy('sort_order')->get(); $categories->each(function($category) { diff --git a/models/category/columns.yaml b/models/category/columns.yaml index c2e55a7..3f4ee3c 100644 --- a/models/category/columns.yaml +++ b/models/category/columns.yaml @@ -12,6 +12,9 @@ columns: slug: label: Slug searchable: false + sort_order: + label: Sort Order + searchable: false description: label: Description searchable: false diff --git a/models/category/fields.yaml b/models/category/fields.yaml index 89b5696..68b9dae 100644 --- a/models/category/fields.yaml +++ b/models/category/fields.yaml @@ -16,3 +16,7 @@ fields: description: label: Description type: textarea + sort_order: + label: Sort Order + required: true + type: number diff --git a/updates/create_categories_table.php b/updates/create_categories_table.php index e212932..b080e67 100644 --- a/updates/create_categories_table.php +++ b/updates/create_categories_table.php @@ -14,6 +14,7 @@ public function up() $table->increments('id'); $table->string('title')->index(); $table->string('slug')->unique(); + $table->integer('sort_order')->default(1); $table->string('description')->nullable(); $table->timestamps(); }); diff --git a/updates/demo_seed.php b/updates/demo_seed.php index 9266113..6511966 100644 --- a/updates/demo_seed.php +++ b/updates/demo_seed.php @@ -9,11 +9,11 @@ class DemoSeed extends Seeder { public function run() { $this->createCategories([[ - 'Books', 'books', + 'Books', 'books', 1, 'Here be some books up fer grabs!' ], [ - 'Games & Consoles', 'games-consoles', + 'Games & Consoles', 'games-consoles', 2, 'Bored? Twiddle yer thumbs on these new titles...' ]]); @@ -46,7 +46,8 @@ public function createCategories($categories) $c = new Category; $c->title = $category[0]; $c->slug = $category[1]; - $c->description = $category[2]; + $c->sort_order = $category[2]; + $c->description = $category[3]; $c->save(); } }