Support the ongoing development of Laravel.io →
Views Blade
Last updated 2 years ago.
0

sort of

{!! Form::select('category_id', listSelect(App\Category::all()), null, array('class' => 'form-control','multiple' => TRUE)) !!}
// add to /app/helpers.php
function listSelect($categories){
    $cats = $parents = array();
    $cats['-1']= 'Select Category';

    foreach ($categories as $category) {
        if ($category->parent_id == 0) {
            $parents[$category->id] = $category->name;
            $cats[$category->name]=array();
        }
    }
    foreach ($categories as $category) {
        if($category->parent_id > 0) {
            $parent_name = $parents[$category->parent_id];
            $cats[$parent_name][$category->id]=$category->name;
        }
    }
    return $cats;
}
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

tamirh67 tamirh67 Joined 24 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.