Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Make categories resource sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
eleriojavere committed Aug 4, 2021
1 parent 08b417e commit dd1c717
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"optimistdigital/nova-locale-field": "^2.0",
"whitecube/nova-flexible-content": "^0.2.4",
"optimistdigital/nova-multiselect-field": ">=1.8.1",
"digital-creative/conditional-container": "^1.3"
"digital-creative/conditional-container": "^1.3",
"optimistdigital/nova-sortable": "^2.3.4"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class AddSortOrderToCategory extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$categoriesTable = config('nova-blog.blog_categories_table', 'nova_blog_categories');
Schema::table($categoriesTable, function (Blueprint $table) {
$table->integer('sort_order');
});

DB::statement("UPDATE $categoriesTable SET sort_order = id");
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
10 changes: 9 additions & 1 deletion src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

namespace OptimistDigital\NovaBlog\Models;

use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use Illuminate\Database\Eloquent\Model;

class Category extends Model
class Category extends Model implements Sortable
{
use SortableTrait;

public $sortable = [
'order_column_name' => 'sort_order',
'sort_when_creating' => true,
];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
Expand Down
2 changes: 2 additions & 0 deletions src/Nova/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use OptimistDigital\NovaBlog\Nova\Fields\Slug;
use OptimistDigital\NovaSortable\Traits\HasSortableRows;

class Category extends TemplateResource
{
use HasSortableRows;

public static $displayInNavigation = false;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Nova/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function fields(Request $request)

if (config('nova-blog.include_froala_texteditor_option')) {
$postContent->addLayout('Text section in Froala', 'text_froala', [
Froala::make('Text section in Froala', 'text_content_froala'),
Froala::make('Text section in Froala', 'text_content_froala')
]);
}

Expand Down

0 comments on commit dd1c717

Please sign in to comment.