Skip to content

Commit

Permalink
Add support for specifying sort order, closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
dshoreman committed Oct 20, 2014
1 parent 81c77f3 commit 47df597
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function prepareVars()

public function listCategories()
{
$categories = ShopCategory::all();
$categories = ShopCategory::orderBy('sort_order')->get();

$categories->each(function($category)
{
Expand Down
3 changes: 3 additions & 0 deletions models/category/columns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ columns:
slug:
label: Slug
searchable: false
sort_order:
label: Sort Order
searchable: false
description:
label: Description
searchable: false
Expand Down
4 changes: 4 additions & 0 deletions models/category/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ fields:
description:
label: Description
type: textarea
sort_order:
label: Sort Order
required: true
type: number
1 change: 1 addition & 0 deletions updates/create_categories_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
7 changes: 4 additions & 3 deletions updates/demo_seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...'
]]);

Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 47df597

Please sign in to comment.