I am using Laravel-nestedset and am having a hard time querying the ancestrosOf
my category model.
This is what I am trying to do:
Works
http://carnival-experts.test/categories (this gives me a list of all categories)
http://carnival-experts.test/categories/carnival-games (this gives me a list of all Carnival Games)
Does Not Work
http://carnival-experts.test/categories/carnival-games/large-scale-games (this shows me a list of Carnival Games and not the Large Scale Games category)
I am sure this is just my lack of understanding--any help appreciated.
web.php
...
Route::get('/', 'CategoryController@index')->name('categories');
Route::get('/{category}/{slug?}', 'CategoryController@show')->name('show');
...
CategoryController.php
...
class CategoryController extends Controller
{
public function index()
{
$categories = Category::get()->toTree();
return view('categories.index', compact('categories'));
}
public function show(Category $category, $slug = null)
{
if (!is_null($slug)) {
$categories = Category::ancestorsOf($category);
return view('categories.show_subcategory', compact('categories', 'category', 'slug'));
} else {
return view('categories.show', compact('category'));
}
}
}
show_category.blade.php
...
@foreach($category['children']->chunk(3) as $chunk)
<div class="row">
@foreach($chunk as $category)
<div class="col-md-4" style="margin-bottom: 2rem">
<div class="feature-box center media-box fbox-bg">
<div class="fbox-media">
<a href="/categories/">
<img class="image_fade"
src="https://*****.s3-us-west-1.amazonaws.com/"
alt="Featured Box Image"
style="opacity: 1;"></a>
</div>
<div class="fbox-desc">
<h3></h3>
<span><a href="/categories/">Learn More</a></span>
</div>
</div>
</div>
Products
@if(count($category->products) > 0)
@foreach($category->products as $product)
@endforeach
@endif
@endforeach
</div>
@endforeach
...
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2P4YBev
via IFTTT
Aucun commentaire:
Enregistrer un commentaire