Skip to content

Conversation

@fouedmoussi
Copy link

@fouedmoussi fouedmoussi commented Dec 3, 2019

A method isChild() was added to src/SortableCheckboxes.php that checks whether the current checkbox is a child

Usage Exemple :

/**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
public function fields(Request $request)
{
    $checkBoxes = [];
    $categories = Category::with('subCategories')->get();

    foreach ($categories as $category) {
              $checkBoxes [] = Checkboxes::make('', 'categories')
                     ->options([$category->id => $category->name])
                     ->withoutTypeCasting()->hideFromIndex();
        
       foreach ($category->subCategories as $subCategory) {
                $checkBoxes [] = Checkboxes::make('', 'sub_categories')
                     ->options([$subCategory->id => $subCategory->name])
                     ->isChild()
                     ->withoutTypeCasting()->hideFromIndex();
       }

   } 
   return $checkBoxes;
}

Display result :

formPreview

@maherelgamil
Copy link

Please review this pull request

@m2de
Copy link
Contributor

m2de commented Feb 7, 2020

Apologies for the delay in responding to this and thanks for the PR @fouedmoussi .

Looks like a useful addition. My only issue with this is the replaced formPreview screenshot. If you could either put the original back in or include something that more closely matches the original, that would be great.

Thanks again.

@StanMenten-bp
Copy link

Is it possible to merge this pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants