]> BookStack Code Mirror - bookstack/commitdiff
Added indexes, Reduced queries on pages
authorDan Brown <redacted>
Thu, 26 Nov 2015 23:45:04 +0000 (23:45 +0000)
committerDan Brown <redacted>
Thu, 26 Nov 2015 23:45:04 +0000 (23:45 +0000)
19 files changed:
.gitignore
app/Book.php
app/Chapter.php
app/Http/Controllers/BookController.php
app/Http/Controllers/ChapterController.php
app/Http/Controllers/PageController.php
app/Page.php
app/Repos/BookRepo.php
app/User.php
composer.json
composer.lock
config/app.php
database/factories/ModelFactory.php
database/migrations/2015_11_26_221857_add_entity_indexes.php [new file with mode: 0644]
database/seeds/DummyContentSeeder.php [new file with mode: 0644]
resources/views/books/show.blade.php
resources/views/chapters/show.blade.php
resources/views/pages/show.blade.php
resources/views/pages/sidebar-tree-list.blade.php

index 832184a61ed25782ea27e4bdab03651e48e378b5..ca78584387c8706c0f1f642c16ec1d64316c58e8 100644 (file)
@@ -11,4 +11,5 @@ Homestead.yaml
 /public/bower
 /public/build
 /storage/images
-_ide_helper.php
\ No newline at end of file
+_ide_helper.php
+/storage/debugbar
\ No newline at end of file
index 66ac883ef366b1509645f1efda93cc10ec2f2a2b..de1841459ae26ecc8932ecb912324813a32cd866 100644 (file)
@@ -27,16 +27,6 @@ class Book extends Entity
         return $this->hasMany('BookStack\Chapter');
     }
 
-    public function children()
-    {
-        $pages = $this->pages()->where('chapter_id', '=', 0)->get();
-        $chapters = $this->chapters()->get();
-        foreach($chapters as $chapter) {
-            $pages->push($chapter);
-        }
-        return $pages->sortBy('priority');
-    }
-
     public function getExcerpt($length = 100)
     {
         return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
index ce131f3148d38686727b8ce160b43a30240c310c..c3001b69bd43778c2228f907901f5d3d8823b304 100644 (file)
@@ -18,7 +18,8 @@ class Chapter extends Entity
 
     public function getUrl()
     {
-        return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
+        $bookSlug = isset($this->bookSlug) ? $this->bookSlug : $this->book->slug;
+        return '/books/' . $bookSlug. '/chapter/' . $this->slug;
     }
 
     public function getExcerpt($length = 100)
index 682fc5415568ec3e81efbbe318f3da81b085625d..c4173730dde2db26f74b29ef74e961a8addf462d 100644 (file)
@@ -89,7 +89,8 @@ class BookController extends Controller
     {
         $book = $this->bookRepo->getBySlug($slug);
         Views::add($book);
-        return view('books/show', ['book' => $book, 'current' => $book]);
+        $bookChildren = $this->bookRepo->getChildren($book);
+        return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]);
     }
 
     /**
index 0aa1b6ee2033a4d6291e20001cd0d409c0079cb9..42ae113559260b8fdc29325afb2e016b9cee4077 100644 (file)
@@ -80,8 +80,9 @@ class ChapterController extends Controller
     {
         $book = $this->bookRepo->getBySlug($bookSlug);
         $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
+        $sidebarTree = $this->bookRepo->getChildren($book);
         Views::add($chapter);
-        return view('chapters/show', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
+        return view('chapters/show', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter, 'sidebarTree' => $sidebarTree]);
     }
 
     /**
index e061cea1bbd809ed505c1710b55d93f8b83bdb6e..d9d53178e274629ebfa27981d6be5b05c714712e 100644 (file)
@@ -87,8 +87,9 @@ class PageController extends Controller
     {
         $book = $this->bookRepo->getBySlug($bookSlug);
         $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+        $sidebarTree = $this->bookRepo->getChildren($book);
         Views::add($page);
-        return view('pages/show', ['page' => $page, 'book' => $book, 'current' => $page]);
+        return view('pages/show', ['page' => $page, 'book' => $book, 'current' => $page, 'sidebarTree' => $sidebarTree]);
     }
 
     /**
index 25bb22f8a506e2e1ef40e1d8fae80d5047276a49..feedb1eae85812b27d814582cbd4e061de73faf6 100644 (file)
@@ -40,7 +40,9 @@ class Page extends Entity
 
     public function getUrl()
     {
-        return '/books/' . $this->book->slug . '/page/' . $this->slug;
+        // TODO - Extract this and share with chapters
+        $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
+        return '/books/' . $bookSlug . '/page/' . $this->slug;
     }
 
     public function getExcerpt($length = 100)
index b7189aaf0fbf7712c61838a04499aa4cb9dc4e03..112971a27fbf468aeea744be26d039bd70508198 100644 (file)
@@ -178,6 +178,30 @@ class BookRepo
         return $slug;
     }
 
+    /**
+     * Get all child objects of a book.
+     * Returns a sorted collection of Pages and Chapters.
+     * Loads the bookslug onto child elements to prevent access database access for getting the slug.
+     * @param Book $book
+     * @return mixed
+     */
+    public function getChildren(Book $book)
+    {
+        $pages = $book->pages()->where('chapter_id', '=', 0)->get();
+        $chapters = $book->chapters()->with('pages')->get();
+        $children = $pages->merge($chapters);
+        $bookSlug = $book->slug;
+        $children->each(function ($child) use ($bookSlug) {
+            $child->setAttribute('bookSlug', $bookSlug);
+            if ($child->isA('chapter')) {
+                $child->pages->each(function ($page) use ($bookSlug) {
+                    $page->setAttribute('bookSlug', $bookSlug);
+                });
+            }
+        });
+        return $children->sortBy('priority');
+    }
+
     /**
      * Get books by search term.
      * @param $term
index ffe41229b5e74cbb4df1093e95eadf8034d4f014..570789f37423d9f9ab8cdf7c5c82ad932ac2c42b 100644 (file)
@@ -33,6 +33,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     protected $hidden = ['password', 'remember_token'];
 
+    /**
+     * This holds the user's permissions when loaded.
+     * @var array
+     */
+    protected $permissions;
+
     /**
      * Returns a default guest user.
      */
@@ -40,7 +46,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
     {
         return new static([
             'email' => 'guest',
-            'name'  => 'Guest'
+            'name' => 'Guest'
         ]);
     }
 
@@ -58,7 +64,19 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
 
     public function getRoleAttribute()
     {
-        return $this->roles()->first();
+        return $this->roles()->with('permissions')->first();
+    }
+
+    /**
+     * Loads the user's permissions from thier role.
+     */
+    private function loadPermissions()
+    {
+        if (isset($this->permissions)) return;
+        $this->load('roles.permissions');
+        $permissions = $this->roles[0]->permissions;
+        $permissionsArray = $permissions->pluck('name')->all();
+        $this->permissions = $permissionsArray;
     }
 
     /**
@@ -68,14 +86,11 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     public function can($permissionName)
     {
-        if($this->email == 'guest') {
+        if ($this->email == 'guest') {
             return false;
         }
-        $permissions = $this->role->permissions()->get();
-        $permissionSearch = $permissions->search(function ($item, $key) use ($permissionName) {
-            return $item->name == $permissionName;
-        });
-        return $permissionSearch !== false;
+        $this->loadPermissions();
+        return array_search($permissionName, $this->permissions) !== false;
     }
 
     /**
@@ -114,7 +129,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     public function hasSocialAccount($socialDriver = false)
     {
-        if($socialDriver === false) {
+        if ($socialDriver === false) {
             return $this->socialAccounts()->count() > 0;
         }
 
index 19bf5b08f172be1ab1a8ca4c843d74519bc44d91..d64fc4b283e90c90584f148c731d415c9b37d2c6 100644 (file)
@@ -9,7 +9,8 @@
         "laravel/framework": "5.1.*",
         "intervention/image": "^2.3",
         "barryvdh/laravel-ide-helper": "^2.1",
-        "laravel/socialite": "^2.0"
+        "laravel/socialite": "^2.0",
+        "barryvdh/laravel-debugbar": "^2.0"
     },
     "require-dev": {
         "fzaninotto/faker": "~1.4",
index e847bcb4abec74af89029d75d7c00bf8952cdf5d..485ee353cb9952be13b08369da7d0dfabb9a4fff 100644 (file)
@@ -4,8 +4,63 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "7d7e80e9f1c13417c35195f79e41c038",
+    "hash": "c216d0bcb72b4f2008d7fa8067da2f77",
+    "content-hash": "3c421ae5b8e5c11792249142cb96ff25",
     "packages": [
+        {
+            "name": "barryvdh/laravel-debugbar",
+            "version": "v2.0.6",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/barryvdh/laravel-debugbar.git",
+                "reference": "23672cbbe78278ff1fdb258caa0b1de7b5d0bc0c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/23672cbbe78278ff1fdb258caa0b1de7b5d0bc0c",
+                "reference": "23672cbbe78278ff1fdb258caa0b1de7b5d0bc0c",
+                "shasum": ""
+            },
+            "require": {
+                "illuminate/support": "~5.0.17|5.1.*",
+                "maximebf/debugbar": "~1.10.2",
+                "php": ">=5.4.0",
+                "symfony/finder": "~2.6"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.1-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Barryvdh\\Debugbar\\": "src/"
+                },
+                "files": [
+                    "src/helpers.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Barry vd. Heuvel",
+                    "email": "[email protected]"
+                }
+            ],
+            "description": "PHP Debugbar integration for Laravel",
+            "keywords": [
+                "debug",
+                "debugbar",
+                "laravel",
+                "profiler",
+                "webprofiler"
+            ],
+            "time": "2015-09-09 11:39:27"
+        },
         {
             "name": "barryvdh/laravel-ide-helper",
             "version": "v2.1.0",
             ],
             "time": "2015-08-22 09:49:14"
         },
+        {
+            "name": "maximebf/debugbar",
+            "version": "v1.10.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/maximebf/php-debugbar.git",
+                "reference": "30e53e8a28284b69dd223c9f5ee8957befd72636"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30e53e8a28284b69dd223c9f5ee8957befd72636",
+                "reference": "30e53e8a28284b69dd223c9f5ee8957befd72636",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3.0",
+                "psr/log": "~1.0",
+                "symfony/var-dumper": "~2.6"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.0"
+            },
+            "suggest": {
+                "kriswallsmith/assetic": "The best way to manage assets",
+                "monolog/monolog": "Log using Monolog",
+                "predis/predis": "Redis storage"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.10-dev"
+                }
+            },
+            "autoload": {
+                "psr-0": {
+                    "DebugBar": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Maxime Bouroumeau-Fuseau",
+                    "email": "[email protected]",
+                    "homepage": "http://maximebf.com"
+                }
+            ],
+            "description": "Debug bar in the browser for php application",
+            "homepage": "https://github.com/maximebf/php-debugbar",
+            "keywords": [
+                "debug"
+            ],
+            "time": "2015-10-19 20:35:12"
+        },
         {
             "name": "monolog/monolog",
             "version": "1.16.0",
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/ClassLoader.git",
+                "url": "https://github.com/symfony/class-loader.git",
                 "reference": "2fccbc544997340808801a7410cdcb96dd12edc4"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/ClassLoader/zipball/2fccbc544997340808801a7410cdcb96dd12edc4",
+                "url": "https://api.github.com/repos/symfony/class-loader/zipball/2fccbc544997340808801a7410cdcb96dd12edc4",
                 "reference": "2fccbc544997340808801a7410cdcb96dd12edc4",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/Console.git",
+                "url": "https://github.com/symfony/console.git",
                 "reference": "d6cf02fe73634c96677e428f840704bfbcaec29e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Console/zipball/d6cf02fe73634c96677e428f840704bfbcaec29e",
+                "url": "https://api.github.com/repos/symfony/console/zipball/d6cf02fe73634c96677e428f840704bfbcaec29e",
                 "reference": "d6cf02fe73634c96677e428f840704bfbcaec29e",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/CssSelector.git",
+                "url": "https://github.com/symfony/css-selector.git",
                 "reference": "0b5c07b516226b7dd32afbbc82fe547a469c5092"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/CssSelector/zipball/0b5c07b516226b7dd32afbbc82fe547a469c5092",
+                "url": "https://api.github.com/repos/symfony/css-selector/zipball/0b5c07b516226b7dd32afbbc82fe547a469c5092",
                 "reference": "0b5c07b516226b7dd32afbbc82fe547a469c5092",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/Debug.git",
+                "url": "https://github.com/symfony/debug.git",
                 "reference": "9daa1bf9f7e615fa2fba30357e479a90141222e3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Debug/zipball/9daa1bf9f7e615fa2fba30357e479a90141222e3",
+                "url": "https://api.github.com/repos/symfony/debug/zipball/9daa1bf9f7e615fa2fba30357e479a90141222e3",
                 "reference": "9daa1bf9f7e615fa2fba30357e479a90141222e3",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/DomCrawler.git",
+                "url": "https://github.com/symfony/dom-crawler.git",
                 "reference": "9dabece63182e95c42b06967a0d929a5df78bc35"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/DomCrawler/zipball/9dabece63182e95c42b06967a0d929a5df78bc35",
+                "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/9dabece63182e95c42b06967a0d929a5df78bc35",
                 "reference": "9dabece63182e95c42b06967a0d929a5df78bc35",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/EventDispatcher.git",
+                "url": "https://github.com/symfony/event-dispatcher.git",
                 "reference": "9310b5f9a87ec2ea75d20fec0b0017c77c66dac3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
+                "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
                 "reference": "9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/HttpFoundation.git",
+                "url": "https://github.com/symfony/http-foundation.git",
                 "reference": "863af6898081b34c65d42100c370b9f3c51b70ca"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/863af6898081b34c65d42100c370b9f3c51b70ca",
+                "url": "https://api.github.com/repos/symfony/http-foundation/zipball/863af6898081b34c65d42100c370b9f3c51b70ca",
                 "reference": "863af6898081b34c65d42100c370b9f3c51b70ca",
                 "shasum": ""
             },
             "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/HttpKernel.git",
+                "url": "https://github.com/symfony/http-kernel.git",
                 "reference": "405d3e7a59ff7a28ec469441326a0ac79065ea98"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/405d3e7a59ff7a28ec469441326a0ac79065ea98",
+                "url": "https://api.github.com/repos/symfony/http-kernel/zipball/405d3e7a59ff7a28ec469441326a0ac79065ea98",
                 "reference": "405d3e7a59ff7a28ec469441326a0ac79065ea98",
                 "shasum": ""
             },
index 196a5c19b95e2e08f4b3506e4654ca0d9c524337..aa7c0b561fccb65e309f5e882aa9f05dd77f12f4 100644 (file)
@@ -143,6 +143,7 @@ return [
          */
         Intervention\Image\ImageServiceProvider::class,
         Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
+        Barryvdh\Debugbar\ServiceProvider::class,
 
 
         /*
@@ -207,6 +208,7 @@ return [
          */
 
         'ImageTool' => Intervention\Image\Facades\Image::class,
+        'Debugbar' => Barryvdh\Debugbar\Facade::class,
 
         /**
          * Custom
index 6a1ab049cb7bac695161c687e1f6f97ee533df57..31c7a3716689428b4495e930ef210f13190b12cf 100644 (file)
@@ -23,6 +23,7 @@ $factory->define(BookStack\User::class, function ($faker) {
 $factory->define(BookStack\Book::class, function ($faker) {
     return [
         'name'        => $faker->sentence,
+        'slug'        => str_random(10),
         'description' => $faker->paragraph
     ];
 });
@@ -30,6 +31,7 @@ $factory->define(BookStack\Book::class, function ($faker) {
 $factory->define(BookStack\Chapter::class, function ($faker) {
     return [
         'name'        => $faker->sentence,
+        'slug'        => str_random(10),
         'description' => $faker->paragraph
     ];
 });
@@ -37,6 +39,7 @@ $factory->define(BookStack\Chapter::class, function ($faker) {
 $factory->define(BookStack\Page::class, function ($faker) {
     return [
         'name' => $faker->sentence,
+        'slug'        => str_random(10),
         'html' => '<p>' . implode('</p>', $faker->paragraphs(5)) . '</p>'
     ];
 });
diff --git a/database/migrations/2015_11_26_221857_add_entity_indexes.php b/database/migrations/2015_11_26_221857_add_entity_indexes.php
new file mode 100644 (file)
index 0000000..4e68dd6
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddEntityIndexes extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('books', function (Blueprint $table) {
+            $table->index('slug');
+            $table->index('created_by');
+            $table->index('updated_by');
+        });
+        Schema::table('pages', function (Blueprint $table) {
+            $table->index('slug');
+            $table->index('book_id');
+            $table->index('chapter_id');
+            $table->index('priority');
+            $table->index('created_by');
+            $table->index('updated_by');
+        });
+        Schema::table('page_revisions', function (Blueprint $table) {
+            $table->index('page_id');
+        });
+        Schema::table('chapters', function (Blueprint $table) {
+            $table->index('slug');
+            $table->index('book_id');
+            $table->index('priority');
+            $table->index('created_by');
+            $table->index('updated_by');
+        });
+        Schema::table('activities', function (Blueprint $table) {
+            $table->index('book_id');
+            $table->index('user_id');
+            $table->index('entity_id');
+        });
+        Schema::table('views', function (Blueprint $table) {
+            $table->index('user_id');
+            $table->index('viewable_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('books', function (Blueprint $table) {
+            $table->dropIndex('slug');
+            $table->dropIndex('created_by');
+            $table->dropIndex('updated_by');
+        });
+        Schema::table('pages', function (Blueprint $table) {
+            $table->dropIndex('slug');
+            $table->dropIndex('book_id');
+            $table->dropIndex('chapter_id');
+            $table->dropIndex('priority');
+            $table->dropIndex('created_by');
+            $table->dropIndex('updated_by');
+        });
+        Schema::table('page_revisions', function (Blueprint $table) {
+            $table->dropIndex('page_id');
+        });
+        Schema::table('chapters', function (Blueprint $table) {
+            $table->dropIndex('slug');
+            $table->dropIndex('book_id');
+            $table->dropIndex('priority');
+            $table->dropIndex('created_by');
+            $table->dropIndex('updated_by');
+        });
+        Schema::table('activities', function (Blueprint $table) {
+            $table->dropIndex('book_id');
+            $table->dropIndex('user_id');
+            $table->dropIndex('entity_id');
+        });
+        Schema::table('views', function (Blueprint $table) {
+            $table->dropIndex('user_id');
+            $table->dropIndex('entity_id');
+        });
+    }
+}
diff --git a/database/seeds/DummyContentSeeder.php b/database/seeds/DummyContentSeeder.php
new file mode 100644 (file)
index 0000000..d8ab91d
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class DummyContentSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $user = factory(BookStack\User::class, 1)->create();
+        $role = \BookStack\Role::where('name', '=', 'admin')->first();
+        $user->attachRole($role);
+
+
+        $books = factory(BookStack\Book::class, 20)->create(['created_by' => $user->id, 'updated_by' => $user->id])
+            ->each(function($book) use ($user) {
+                $chapters = factory(BookStack\Chapter::class, 5)->create(['created_by' => $user->id, 'updated_by' => $user->id])
+                    ->each(function($chapter) use ($user, $book){
+                       $pages = factory(\BookStack\Page::class, 10)->make(['created_by' => $user->id, 'updated_by' => $user->id, 'book_id' => $book->id]);
+                        $chapter->pages()->saveMany($pages);
+                    });
+                $book->chapters()->saveMany($chapters);
+            });
+    }
+}
index 0485ccc156dcd8922481aa9752e28c5363d92adf..1b6009504a24b42d5fcea8b645f4fdc3f3dc40e3 100644 (file)
@@ -37,8 +37,8 @@
 
                     <div class="page-list">
                         <hr>
-                        @if(count($book->children()) > 0)
-                            @foreach($book->children() as $childElement)
+                        @if(count($bookChildren) > 0)
+                            @foreach($bookChildren as $childElement)
                                 @if($childElement->isA('chapter'))
                                     @include('chapters/list-item', ['chapter' => $childElement])
                                 @else
index 60965d0f6afd3003937505e5fd7470fc208b4615..75ae6bf65d938dea6914c35db589b3ec2b128ed4 100644 (file)
@@ -60,7 +60,7 @@
                 </p>
             </div>
             <div class="col-md-3 col-md-offset-1">
-                @include('pages/sidebar-tree-list', ['book' => $book])
+                @include('pages/sidebar-tree-list', ['book' => $book, 'sidebarTree' => $sidebarTree])
             </div>
         </div>
     </div>
index 937d52be14e1d859f9a708a154327e01f1f22b99..2a0fcc14de341bcc773db8154ea549984f84f424 100644 (file)
@@ -60,7 +60,7 @@
             </div>
             <div class="col-md-3 print-hidden">
 
-                @include('pages/sidebar-tree-list', ['book' => $book])
+                @include('pages/sidebar-tree-list', ['book' => $book, 'sidebarTree' => $sidebarTree])
 
             </div>
         </div>
index 9338cbab876d6da16ae19a9779288be59579799f..76d3a76141c4cb8b69b7b06d596845b317614a84 100644 (file)
@@ -3,7 +3,7 @@
     <h6 class="text-muted">Book Navigation</h6>
     <ul class="sidebar-page-list menu">
         <li class="book-header"><a href="{{$book->getUrl()}}" class="book {{ $current->matches($book)? 'selected' : '' }}"><i class="zmdi zmdi-book"></i>{{$book->name}}</a></li>
-        @foreach($book->children() as $bookChild)
+        @foreach($sidebarTree as $bookChild)
             <li class="list-item-{{ $bookChild->getName() }}">
                 <a href="{{$bookChild->getUrl()}}" class="{{ $bookChild->getName() }} {{ $current->matches($bookChild)? 'selected' : '' }}">
                     @if($bookChild->isA('chapter'))<i class="zmdi zmdi-collection-bookmark"></i>@else <i class="zmdi zmdi-file-text"></i>@endif{{ $bookChild->name }}