Skip to content

Commit

Permalink
fix:模型计数方式
Browse files Browse the repository at this point in the history
  • Loading branch information
hui-ho committed Sep 25, 2019
1 parent 5ab8ce2 commit cddbc06
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 0 additions & 5 deletions app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ class Category extends Model
{
use ModelTree, AdminBuilder;

public function setChildrenCountAttribute()
{
return count($this->children);
}

public function children()
{
return $this->hasMany(static::class, 'parent_id');
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class HomeController extends Controller
{
public function index()
{

$categories = Category::with(['children' => function ($query) {
$query->orderBy('order');
}, 'sites'])->orderBy('order')->get();
}, 'sites'])
->withCount('children')
->orderBy('order')
->get();

return view('index')->with('categories', $categories);
}
Expand Down
2 changes: 1 addition & 1 deletion config/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
'enable' => true,
],
'material-ui' => [
'enable' => false
'enable' => true
]
],
];

0 comments on commit cddbc06

Please sign in to comment.