Giter Club home page Giter Club logo

laravel-nestable's Introduction

Laravel 5 Nestable

Laravel Nestable to work with recursive logic. Category level there is no limit but this may vary depending on your server performance. Allow the 100000 recursion process execution since PHP 5.2. More info

Build Status

Install

composer require atayahmet/laravel-nestable

Then

Add to app.php the Service Provider file.

Nestable\NestableServiceProvider::class

Then add app.php Facade file again.

'Nestable' => Nestable\Facades\NestableService::class

Finally run the artisan command:

php artisan vendor:publish --provider="Nestable\NestableServiceProvider"

That's it!

Basic Usage with Eloquent

Suppose that the data came from a database as follows.

Category table:

id parent_id name slug
1 0 T-shirts t-shirts
2 1 Red T-shirts red-t-shirts
3 1 Black T-shirts black-t-shirts
4 0 Sweaters sweaters
5 4 Red Sweaters red-sweaters
6 4 Blue Sweaters blue-sweaters

Example 1:

<?php

use Nestable\NestableTrait;

class Category extends \Eloquent {

    use NestableTrait;

    protected $parent = 'parent_id';

}

Note: $parent variable refers to the parent category (Default parent_id)

<?php

$categories = Category::nested()->get();

Query result:

<?php

array:6 [
      0 => array:5 [
        "id" => 1
        "name" => "T-shirts"
        "slug" => "t-shirts"
        "child" => array:2 [
          0 => array:5 [
            "id" => 2
            "name" => "Red T-shirts"
            "slug" => "red-t-shirts"
            "child" => []
            "parent_id" => 1
          ]
          1 => array:5 [
            "id" => 3
            "name" => "Black T-shirts"
            "slug" => "black-t-shirts"
            "child" => []
            "parent_id" => 1
          ]
        ]
        "parent_id" => 0
      ]
      1 => array:5 [
        "id" => 4
        "name" => "Sweaters"
        "slug" => "sweaters"
        "child" => array:2 [
          0 => array:5 [
            "id" => 5
            "name" => "Red Sweaters"
            "slug" => "red-sweaters"
            "child" => []
            "parent_id" => 4
          ]
          1 => array:5 [
            "id" => 6
            "name" => "Blue Sweaters"
            "slug" => "blue-sweaters"
            "child" => []
            "parent_id" => 4
          ]
        ]
        "parent_id" => 0
    ]
]

For html tree output:

<?php

Category::renderAsHtml();

Output:

<ul>
    <li><a href="">T-shirts
        <ul>
            <li><a href="red-t-shirt">Red T-shirt</a></li>
            <li><a href="black-t-shirts">Black T-shirts</a></li>
        </ul>
    </li>

    <li><a href="">Sweaters
        <ul>
            <li><a href="red-sweaters">Red Sweaters</a></li>
            <li><a href="blue-sweaters">Blue Sweaters</a></li>
        </ul>
    </li>
</ul>

For dropdown output:

<?php

Category::attr(['name' => 'categories'])
    ->selected(2)
    ->renderAsDropdown();

Output:

<select name="categories">
    <option value="1">T-shirts</option>
    <option value="2" selected="selected">  Red T-shirts</option>
    <option value="3">  Black T-shirts</option>

    <option value="4">Sweaters</option>
    <option value="5">  Red Sweaters</option>
    <option value="6">  Blue Sweaters</option>
</select>

Selected for multiple list box:

->selected([1,2,3])

Output methods

name Parameter output
renderAsArray() none array
renderAsJson() none json
renderAsHtml() none html
renderAsDropdown() none dropdown
renderAsMultiple() none Listbox

Usable methods with output methods

renderAsArray()

name paremeter description
parent() int Get childs of the defined parent

renderAsJson()

name paremeter description
parent() int Get childs of the defined parent

renderAsHtml()

name paremeter description
parent() int Get childs of the defined parent
active() callback/array/int Selected item(s) for html output
ulAttr() array/string Add attribute to parent ul element
firstUlAttr() array/string Add attribute to parent ul element
route() callback/array Generate url by route name
customUrl() string Generate custom url

renderAsDropdown()/renderAsMultiple()

name paremeter description
parent() int Get childs of the defined parent
selected() callback/array/int Selected item(s) for dropdown
attr() array Dropdown/listbox attributes

parent()

Get childs of the defined parent.

<?php

Category::parent(2)->renderAsArray();

Note: This methods usable all with output methods

active()

Selected item(s) for html output.

Example 1:

<?php

Menu::active('t-shirts')->renderAsHtml();

Example 2:

<?php

Menu::active('t-shirts', 'black-t-shirts')->renderAsHtml();

Example 3:

<?php

Menu::active(['t-shirts', 'black-t-shirts'])->renderAsHtml();

Example 4:

<?php

Menu::active(function($li, $href, $label) {

    $li->addAttr('class', 'active')->addAttr('data-label', $label);

})->renderAsHtml();

Example 5:

<?php

Menu::active(function($li, $href, $label) {

    $li->addAttr(['class' => 'active', 'data-label' => $label]);

})->renderAsHtml();

firstUlAttr()

Add attribute to first ul element

Example 1:

<?php

Menu::firstUlAttr('class', 'first-ul')->renderAsHtml();

Example 2:

<?php

Menu::firstUlAttr(['class' => 'first-ul'])->renderAsHtml();

ulAttr()

Add attribute to parent ul element

Example 1:

<?php

Menu::ulAttr('class', 'nav-bar')->renderAsHtml();

Example 2:

<?php

Menu::ulAttr(['t-shirts' => 'black-t-shirts'])->renderAsHtml();

Example 3:

<?php

Menu::ulAttr(function($ul, $parent_id) {

    if($parent_id == 10) {
        $ul->ulAttr('class', 'nav-bar');
    }

})->renderAsHtml();

route()

Generate url by route name

Example 1:

<?php

Menu::route(['product' => 'slug'])->renderAsHtml();

Note: product refer to route name and slug refer to paremeter name.

<?php

Route::get('product/{slug}', 'ProductController@show');

Example 2:

<?php

Menu::route(function($href, $label, $parent) {

    return \URL::to($href);

})->renderAsHtml();

customUrl()

Generate custom url with slug

Example 1:

<?php

Menu::customUrl('product/detail/{slug}')->renderAsHtml();

Example 1:

<?php

Menu::customUrl('product/{slug}/detail')->renderAsHtml();

Note: slug keyword belongs to html > href in config file.

selected()

Selected item(s) for dropdown.

Example 1:

<?php

Category::selected(1)->renderAsDropdown();

Example 2:

<?php

Category::selected(1,5)->renderAsMultiple();

Example 3:

<?php

Category::selected([1,3])->renderAsMultiple();

Example 4:

<?php

Category::selected(function($option, $value, $label) {

    $option->addAttr('selected', 'true');
    $option->addAttr(['data-item' => $label]);

})->renderAsMultiple();

attr()

Dropdown/listbox attributes.

<?php

Category::attr(['name' => 'categories', 'class' => 'red'])->renderAsDropdown();

Configuration

The above examples were performed with default settings. Config variables in config/nestable.php file.

name type description
parent string Parent category column name
primary_key string Table primary key
generate_url boolean Generate the url for html output
childNode string Child node name
body array Array output (default)
html array Html output columns
dropdown array Dropdown/Listbox output

body

The body variable should be an array and absolutely customizable.

Example:

<?php

'body' => [
    'id',
    'category_name',
    'category_slug'
]

html

Configuration for html output.

name description
label Label column name
href Url column name

Example:

<?php

'html' => [
    'label' => 'name',
    'href'  => 'slug',
]

dropdown

Configuration for dropdown/listbox output.

name description
prefix Label prefix
label Label column name
value Value column name

Example:

<?php

'dropdown' => [
    'prefix' => '-',
    'label'  => 'name',
    'value'  => 'id'
]

Using Independent Models

Include the Nestable facade.

<?php

use Nestable;

$result = Nestable::make([
    [
        'id' => 1,
        'parent_id' => 0,
        'name' => 'T-shirts',
        'slug' => 't-shirts'
    ],
    [
        'id' => 2,
        'parent_id' => 1,
        'name' => 'Red T-shirts',
        'slug' => 'red-t-shirts'
    ],
    [
        'id' => 3,
        'parent_id' => 1,
        'name' => 'Black T-shirts',
        'slug' => 'black-t-shirts'
    ]
    // and more...
]);

For array output:

$result->renderAsArray();

Validators

It controls the structure of the data. They also made the rendering process with a second parameter control after they.

name Parameters
isValidForArray boolean
isValidForJson boolean
isValidForHtml boolean
isValidForDropdown boolean
isValidForMultiple boolean

Example 1:

<?php

Menu::make($categories)->isValidForHtml();

// return true or false

Example 2:

<?php

Menu::make($categories)->isValidForHtml(true);

// return html string if data valid

Macros

<?php

Nestable::macro('helloWorld', function($nest, $categories) {

    return $nest->make($categories)->active('sweater')->route(['tests' => 'slug'])->renderAsHtml();

});

Call the above macro:

<?php

$categories = [

    [
        'id'        => 1,
        'parent_id' => 0,
        'name'      => 'T-shirt',
        'slug'      => 'T-shirt'
    ],
    [
        'id'        => 2,
        'parent_id' => 0,
        'name'      => 'Sweater',
        'slug'      => 'sweater'
    ]

];

Nestable::helloWorld($categories);

Helper

<?php

nestable($data)->renderAsHtml();
<?php

nestable()->make($data)->renderAsHtml();
<?php

nestable()->macro('helloWorld', function() {
    return 'Hello Laravel';
});

// run
nestable()->helloWorld();

laravel-nestable's People

Contributors

ahmed-aliraqi avatar atayahmet avatar kleiberd avatar mshoaibdev avatar sarav-s avatar sedehi avatar vaughany avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-nestable's Issues

NestableService.php#303 count(): Parameter must be an array or an object that implements Countable

Before the update worked

composer.json
"atayahmet/laravel-nestable": "^0.8.4",
count(): Parameter must be an array or an object that implements Countable
/srv/http/projects/artvitrina/vendor/atayahmet/laravel-nestable/src/Services/NestableService.php#303
ErrorException
            $tree = $first ? '<select '.$this->addAttributes().' ' : '';
        }
        // if pass array data to selected method procces will generate multiple dropdown menu.
        if ($first && (count($this->selected) > 1 || $this->multiple == true)) {
            $tree .= ' multiple';
        }

PHP 7.2.0 Issue on NestableService.php

I upgrade to PHP 7.2.0 and facing this error

count(): Parameter must be an array or an object that implements Countable on vendor/atayahmet/laravel-nestable/src/Services/NestableService.php line 406

Then to fix this, I change this

if (count(func_num_args()) < 3) {
    $data = $this->data;
    $key = $this->parent;
    $value = current(func_get_args());
}

into this

if (func_num_args() < 3) {
    $data = $this->data;
    $key = $this->parent;
    $value = current(func_get_args());
}

Let me know if there is a better solution. Thanks.

renderAsDropdown Getting white page

Hi Atayahmet,

I Am using atayahmet/laravel-nestable plug.

As per document i installed your package everything is fine but i want my categories in drop down.
For that i used like

                    EventCategory::attr(['name' => 'categories'])
                        ->selected(1)
                        ->renderAsDropdown(); 

in my view file its getting white page.

I am using laravel5.5 and php 7 versions

Please suggest me where i did mistake.

Thanks in advance.

Add New Field

Hai,

How to add new field ? I try modify nested.php in config but not show new field

Thanks

Output in 3 columns

Hi guys! This is a great library! Tell me how I can output this style:

page:

Category 1         | Category 4         | Category 7
Subcategories 1    | Subcategories 4    | Subcategories 7
Category 2         | Category 5         | Category 8
Subcategories 2    | Subcategories 5    | Subcategories 8
Category 3         | Category 6         | Category 9
Subcategories 3    | Subcategories 6    | Subcategories 9

Add Attributes to <ul> and <li>

hi dear @atayahmet
i want to add some attributes to <ul>
but i didn't see anything in documentation

is it possible in this version?
if it's not, how i can add this feature to the package?

edit:
i solved this by modifing NestableService.php (only worked for parent ul)
i changed renderAsHtml by these codes:

if($first) {
   $tree = $first ? '<ul '.$this->addAttributes().'>' : '';
}

anyway i'm waiting for your update for this package ...
i need attributes for <ul> and <li>
i have a function to generate ul li for nav-menu
so i need dynamic attributes for nested ul and li

Multiple dropdowns using 'nestable($data)'

I'm trying to render multiple dropdowns from level 0 categories, like so:

$categories = Category::nested()->get();

@foreach ( $categories as $category )
{!! nestable($category)->renderAsDropdown() !!}
@endforeach

But getting this error: "Illegal string offset 'parent_id'"..

If i pass it like this:

@foreach ( $categories as $category )
{!! nestable($category['child'])->renderAsDropdown() !!}
@endforeach

It renders empty dropdowns

Can you please explain how to achieve this?

Retrieveing all Model vars.

Thanks for this package.
I've got all things working as I would like other than one thing:
When using Category::nested()->get(); the collection returned only contains the standard vars:

  0 => array:5 [▼
    "id" => 15
    "name" => "General"
    "slug" => "general"
    "child" => array:1 [▶]
    "parent_id" => null
  ]

...however, my category table has a 'color' field, that I would also like returned with the collection.
I have tried addings this variable to the config file:

return [
    'color'=>'color',
    'parent'=> 'parent_id',
    'primary_key' => 'id',

...with no success.
Could you point me int he correct direction to add this functionality please?
Thanks :)

Call to a member function delete() on null in NestableTrait

When I try deleting a record, it is throwing me this error

FatalErrorException in NestableTrait.php line 277:
Call to a member function delete() on null

My Model File

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Nestable\NestableTrait;

class Menu extends Model
{
use NestableTrait;

protected $parent = 'parent_id';

protected $fillable = ['parent_id', 'menu_id', 'name', 'slug', 'status'];
}

integration of Jquery nestable to your package

Have you thought that integrate Jquery nestable to your package?

Jquery Nestable

I tried to make it workable, but there is some missed things in your package.
1 ) Using <ol> instead of ul
2) Adding data-id attribute to <li>. For example:
<li data-id=1>Label</li>

Error in documentation

I think in table "Output methods" in the last row should be renderAsMultiple() instead renderAsDropdown(). Because right now there is renderAsDropdown() twice.

Kategorilere Bağlı Ürünleri Listeletmek

Merhaba üstadım hızır gibi yetiştin maşallah, seninle aynı dili kullanmak güzel :)) şimdi bir alışveris sitesi yapıyorum ve kategorileme kısmını sayende çözmüş bulunmaktayım, lakin şöyle bir sorunum var kategoriye tıkladığım zaman hem tıkladığım kategoriye hemde alt kategoriye bağlı ürünleri göstermek istiyorum bunu yapamadım. bu konuda yardımcı olursan veya yol gösterirsen sevinirim. selamlar saygılar sunuyorum.

Undefined index: id

I have a table "post_categories" with "category_id" as primary key instead of default "id".

I have changed the variable value "primary_key" to "category_id" in "config/nestable.php", but still I am getting "undefined index: id" error.

Embed Placeholder Item (Empty Element) and Bug on selected Item

Hello @atayahmet
This is very awesome plugin so far.. But I found some issues :

  1. How to embed placeholder / empty item in dropdown? Right now it will generate dropdown item from table's record. I got problem when I want to add element <option value="">Please Choose</option>

  2. I try to assign selected item. I code like this:
    ShopCategory::selected(1)->renderAsDropdown() but always generate a multiple type option that I don't want. How to solve this?

  3. It will also break the laravel query builder :( . For example I have code like this:
    ShopCategory::where('parent_id',0)->orderBy('name','ASC')->get() , the condition 'parent_id' = 0 will be ignored.

Thanks

Generating deep url for sub categories

Well, lets look through this example:

<ul>
    <li><a href="">T-shirts
        <ul>
            <li><a href="red-t-shirt">Red T-shirt</a>
                <ul>
                     <li><a href="s-size">S size</a><li>
                     <li><a href="m-size">M size</a><li>
                     <li><a href="l-size">L size</a><li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Is it possible to generate deep url for sub categories?

Instead of
<li><a href="s-size">S size</a><li>

generate
<li><a href="red-t-shirt/s-size">S size</a><li>

Laravel 5.3

hi again dear @atayahmet

i want to upgrade my project to laravel 5.3
but i get an error from your package...
i think we need a laravel-nestable version compatible with L5.3

configuring the link, route

hi i have many nested categories like mechanic-part,car and place but when i render as html and i click in a link it go directly to site.local/{slug}
i want to change to custom link like site.local/car/{slug} site.local/mechanic-part/{slug} .... how can i?

Apply formatting to just children?

If I change the prefix in the nestable.php file it applies it to all options in the list. Is it possible to have it only apply the prefix to just children?

'dropdown' => [
    'prefix' => ' - ',
    'label' => 'name',
    'value' => 'id'
]

screen shot 2017-12-06 at 11 15 17 am

I cannot use Eloquent methods

Hello @atayahmet I've just installed your package to handle categories, but when I use Nestable\NestableTrait all Eloquent methods are not working as where(), findOrFail(), delete() ....
And if I remove NestableTrait everything working good.

Any solutions please ..

where is breadcrumb option, how i can retrieve parents of child?

hello i want to inverse the hierarchy, since each child can have one parent, how i can retrieve the breadcrumb (parents) of a child?

-Electornic
--Computer and tablet
---Computer (want get parent of computer as below)

i want below
Compiter > Computers and Tablets > Electronic

ulAttr not working ?

I have following code but ulAttr not working

$menus = \App\MenuItem::where('menu_id', 1)->get()->toArray();
$menus = nestable($menus)->ulAttr(function($ul, $parent_id) {
		    if($parent_id >= 0) {
		        $ul->ulAttr('class', 'dropdown-menu');
		    }
		})->active(function($li, $href, $label) {
		    	$li->addAttr('class', 'active');
		})->renderAsHtml();
    	dd($menus);

How to use where??

when i am only want to show where parent_id = 0 i got error "Call to undefined method Illuminate\Database\Query\Builder::attr()"

example =

$kategoris = Category::where('parent_id', '=', 0)->attr(['name' => 'category_id', 'class' =>'form-control'])
->selected($selected)
->renderAsDropdown();

if i use parent(0) all the child is rendered.
$kategoris = Category::parent(0)->attr(['name' => 'category_id', 'class' =>'form-control'])
->selected($selected)
->renderAsDropdown();

I only want show where parent_id == 0. can someone help me??

how to get only one category children

Hi !
Thank you so much for this amazing resource,

I want to know if there is a way to only render one category with its children.

for example:

  • cat1 children are : -cat2 and -cat3
  • cat5 no children
  • cat4 no children
  • cat6 no children

how can I only get cat1 with its children: cat2 and cat3

Thank you.

Can't find class Category

Hi all,

Today I started to use Laravel-nestable for creating a selection box, I followed all the steps, and I receive thiserror: Class 'App\Http\Controllers\Category' not found.

I tried looking for a answer but couldnt find it. What am I doing wrong?

I'm using Laravel 5.4.

Here is my code:
`<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator, DB;
use Nestable\NestableTrait;

class FinanceController extends Controller {
use NestableTrait;

protected $parent = 'parent_id';


private $resultsPerPage = 10;

public function index() {
    $results = DB::table('finance')->simplePaginate($this->resultsPerPage);
    $categories = Category::nested()->get();
    

    return view('finance.index', ['results' => $results]);
}

public function create() {
    return view('finance.create');
}

// Function: store
// Description: Check if all the required values are filled in.
// Returned view: finance.index
public function store(Request $request) {
    // First validate if all the required fields are filled in
    $validater = Validator::make($request->all(), [
        'transactionDate' => 'required',
        'transactionDescription'    => 'required|max:255',
        'transactionCategorie' => 'required',
        'transactionPaymentMethod' => 'required',
        'transactionType' => 'required',
        'transactionAmount' => 'required'
    ]);

    if ($validater->passes()) {
        //Insert the data in the database
        $validateInsert = DB::table('finance')->insert([
            'date' => $request->transactionDate,
            'description' => $request->transactionDescription,
            'categorie' => $request->transactionCategorie,
            'paymentMethod' => $request->transactionPaymentMethod,
            'type' => $request->transactionType,
            'amount' => $request->transactionAmount
        ]);

        //Return to the index view
        return view('finance.index');
    } else {
        // If validation failed, return to the previous file, with the errors and inputs
        return redirect('finance.create')->withErrors($validater)->withInput();
    }
}

public function show($id) {
    //
}

public function edit($id) {
    //
}

public function update(Request $request, $id) {
    //
}

public function destroy($id) {
    //
}

// Custom functions

public function overview() {
    $results = DB::table('finance')->simplePaginate($this->resultsPerPage);

    return view('finance.overview', ['results' => $results]);
}

public function print() {
    return view('finance.print');
}

}
`

Laravel Controller ve View üzerinden gösterim

Merhabalar , ahmet bey öncelikle çok teşekkür ederim controller ve view üzerinden kullanımını anlatabilirmisiniz Category::nested()->get() yi blade içerisine mi yazacam yoksa Controller içerisine mi ikisinide denedim view de hiç çalışmadı controller kısmına yazdığımda ise aşağıdaki hatayı aldım sürüm olarak laravel 5.4 kullanıyorum yardımcı olursanız sevinirim

`Undefined index:

in NestableService.php line 183`

i just want a documentation for this bieutifull package

i dont know when to write some things

like those basic things


use Nestable\NestableTrait;

class Category extends \Eloquent {

use NestableTrait;

protected $parent = 'parent_id';

}
Note: $parent variable refers to the parent category (Default parent_id)

get();

ulAttr(['class' => 'sitemap']) - does not work

Previously worked. Now there is no specified class in the generated layout.

php "atayahmet/laravel-nestable": "^0.8.0"

$result = \Nestable::make($prepare_data);
$result->ulAttr(['class' => 'sitemap'])->route(['categories/update' => 'id'])->renderAsHtml();
dump
"""
\n
<ul>\n
\n
<li ><a href="http://laravelshoppingcart.com/admin/categories/update/3">Категория 1 Ру</a><ul class="sitemap">\n
\n
<li ><a href="http://laravelshoppingcart.com/admin/categories/update/6">Под категория 2 Ру</a></li>\n
\n
</ul></li>\n
\n
<li ><a href="http://laravelshoppingcart.com/admin/categories/update/4">Категория 2 Ру</a><ul class="sitemap">\n
\n
<li ><a href="http://laravelshoppingcart.com/admin/categories/update/5">Под категория 1 Ру</a></li>\n
\n
</ul></li>\n
</ul>\n
"""

Memory Problem

Hello,
When I want to use this package I get:

Fatal error: Out of memory (allocated 1470103552) (tried to allocate 262144 bytes) in D:\xampp\htdocs\platform\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 621

After remove Nestable\NestableServiceProvider::class problem fixed.

Now How can I use this package.

Note:I change my memory_limit but yet it need more memory.

use where in output query

hi.
thanks for your nice package.

i created a custom database like this:

id parent_id name slug post_type img
1 0 cat 1 cat-1 posts thumb.jpg
2 1 cat 2 cat-2 posts p.png
3 0 cat 3 cat-3 products pthumb.jpg

i want to show only categories for a specific post_type
can u help me?

Installation problem

Hi,
I'm trying to install the package in Laravel 5.1.46 but I get this error:

composer require atayahmet/laravel-nestable
Using version ^0.8.1 for atayahmet/laravel-nestable
./composer.json has been updated

php artisan clear-compiled
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for atayahmet/laravel-nestable ^0.8.1 -> satisfiable by atayahmet/laravel-nestable[v0.8.1].
- Conclusion: remove laravel/framework v5.1.46
- Conclusion: don't install laravel/framework v5.1.46
- atayahmet/laravel-nestable v0.8.1 requires illuminate/database 5.2.|5.3.|5.4.|5.5. -> satisfiable by illuminate/database[v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.2].
- don't install illuminate/database v5.2.0|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.19|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.21|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.24|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.25|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.26|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.27|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.28|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.31|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.32|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.37|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.43|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.45|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.6|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.2.7|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.3.0|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.3.16|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.3.23|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.3.4|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.0|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.13|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.17|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.19|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.27|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.36|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.4.9|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.5.0|don't install laravel/framework v5.1.46
- don't install illuminate/database v5.5.2|don't install laravel/framework v5.1.46
- Installation request for laravel/framework ~5.1.46 -> satisfiable by laravel/framework[v5.1.46].

Installation failed, reverting ./composer.json to its original content.

Where is the problem?
Thanks!

showing subcategories of a number of categories

Hi,
for example: I want to show a list of all the sub-categories (children) under the categories number [1,2,3],
when I use

$id = [1,2,3];
        $categories = Category::whereIn('id',$id)->renderAsJson();
        return $categories;

it returns only those three categories [1,2,3] and it doesn't return any children.

the same result here :

$categories = Category::whereIn('id',$id)->nested()->get();

There is a function in this package: parent() , but it only works with one parent_id like this:

$id = 1;
$categories = Category::parent($id)->renderAsJson();

Is there any way to fix this?

Thanks for this amazing and easy to use package !

Category by Id

Example category table

id parent_id name slug
1 0 Car car
2 1 BMW bmw
3 1 Benz benz
4 0 Truck truck

Is there any way to get Car's children only?

Current output. Truck category also return

{  
   "id":1,
   "name":"Car",
   "slug":"car",
   "child":[  
      {  
         "id":2,
         "name":"BMW",
         "slug":"bmw"
      },
      {  
         "id":3,
         "name":"Benz",
         "slug":"benz"
      }
   ]
},
{  
   "id":1,
   "name":"Truck",
   "slug":"truck"
}

Make use of optgroup tag

@atayahmet Today I want to create a nestable dropdownlist, with optgroup tag, but I saw there isn't a option for this. Is there a option to add it in?

routing problem

hi again...
i have an issue with routing...
i call your package several times in a page!
it works nice but it set all Urls same ...

$a = category::where('post_type', 'medical')
        ->route(["medical-cat" => 'slug'])
       ->ulAttr(['class' => 'ulClass'])
       ->active(function($li, $href, $label) {
              $li->addAttr('class', 'liClass');
       })
       ->renderAsHtml();

$b = category::where('post_type', 'news')
       ->route(["news-cat" => 'slug'])
       ->ulAttr(['class' => 'ulClass'])
       ->active(function($li, $href, $label) {
              $li->addAttr('class', 'liClass');
       })
       ->renderAsHtml();

dd($a,$b);

routes.php :

Route::get('/medical/{slug}', 'myController@index')->name('medical-cat');
Route::get('/news/{slug}', 'myController@index')->name('news-cat');

result is something like this:

<ul class="ulClass">
    <li  class="liClass">
        <a href="http://domain.com/medical/slug">cat name</a>
    </li>
    <li  class="liClass">
        <a href="http://domain.com/medical/slug">cat name</a>
    </li>
</ul>

<ul class="ulClass">
    <li  class="liClass">
        <a href="http://domain.com/medical/slug">cat name</a>
    </li>
    <li  class="liClass">
        <a href="http://domain.com/medical/slug">cat name</a>
    </li>
</ul>

second ul most have news in url but is medical
i think it's a problem in constructor

selected() placeholder() in renderAsMultiple()

My Goal is to add placeholder with value = 0 and select it.

With this code the placeholder is not selected:
$categories = Category::attr([ 'class' => 'form-control error-input'])
->placeholder(['0', 'Tutte le Categorie'])
->selected([0])
->renderAsMultiple();

I wrong something?

Obviously work if I edit NESTABLESERVICE.php (VENDOR) row 310 with:
if(current($this->placeholder)) {
if ($this->selected == key($this->placeholder)){
$selcted_placeholder = 'selected="selected"';
}else{
$selcted_placeholder = '';
}

$tree .= '<option '.$selcted_placeholder.' value="'.key($this->placeholder).'">' . current($this->placeholder) . '';
}

$categories = Category::nested()->get();

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

First ul attribute

Is there a way to assign an attribute to the parent ul without assigning it to the subsequent children?
I have tried ulAttr(['class' => 'someClass']) but that asigns the class to all the ul elements.

<ul class="someClass">
    <li><a href="">T-shirts
        <ul>
            <li><a href="red-t-shirt">Red T-shirt</a></li>
            <li><a href="black-t-shirts">Black T-shirts</a></li>
        </ul>
    </li>
    <li><a href="">Sweaters
        <ul>
            <li><a href="red-sweaters">Red Sweaters</a></li>
            <li><a href="blue-sweaters">Blue Sweaters</a></li>
        </ul>
    </li>
</ul>

It was updated to version 5.5.23 and the package stopped working.

Package operations: 1 install, 0 updates, 0 removals
  - Installing atayahmet/laravel-nestable (v0.8.2): Loading from cache
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover

In ProviderRepository.php line 208:
                                                             
  Class 'Nestable\NestableServiceProvider::class' not found  
                                                             

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

class yapısı hakkında

selam
Kategorileri listelerken ul ve li lerin classları tam olarak hakkim olamiyor bunlala ilgili nasıl bi yol izlemeliyim.

Not Compatible With Laravel 5.6

Hello Thank You For Your Time Making Good Work Out There 🔥

I Have Installed The Package 📦

On Laravel 5.6 💯 But It's Not Displaying When Using The Methods On Your Package
I May Do Something Wrong

Undefined index:

hi, I am trying to use your packeg. But its showing flowing error.
screenshot_9
And my Table structure is
screenshot_8

please help....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.