Closed ghost closed 6 years ago
Hi @shrikanth003
->nested()
method will return array tree. If you want use in html template, you have to choose a render method.
Example:
{{ Category::renderAsHtml() }}
or:
{{ Category::renderAsDropdown() }}
Please check docs: Outputs
Ok. Is theere any tutorial on this? I mean on how to create a nested categories list with Dependent dropdown
I think this section will be helpfuly: Render as dropdown
My Categories Model Looks Like this
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Nestable\NestableTrait;
class Category extends Model { use NestableTrait; protected $parent = 'parent_id'; }
My Categories Table looks like id, parent_id, name, slug
I have placed {{Category::renderAsHtml()}} on my Website index page.
My Controller looks like this
namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Models\Category;
class PagesController extends Controller { /**
I'm a learner and didn't find any proper tutorial on this. Could you correct me or help me understanding how this works. @atayahmet
Because i get a error Class 'Category' not found (View: D:\xampp\htdocs\myproject\resources\views\index.blade.php)
Ok.The default path for models is the app
directory
You can call this way:
{{ \App\Category::renderAsHtml() }}
But if you want to call with direct model name, run the command below:
Terminal:
$ composer dump-autoload
Now you can use this way:
{{ Category::renderAsHtml() }}
It worked! Tysm :)
This Is Strange The Are No Results When DD(\App\Category::nested()->get())
When Rendering The Category::all(); Indeed It Worked
I Tryied $ composer dump-autoload
Im using laravel 5.5. I have added the package. I have also added the trait to the model,
Where do i need to specify this $categories = Category::nested()->get(); When i do {{$categories = Category::nested()->get();}} it does not show anything on the view