novafieldcheckboxes icon indicating copy to clipboard operation
novafieldcheckboxes copied to clipboard

Allow displaying nested checkboxes

Open fouedmoussi opened this issue 6 years ago • 3 comments

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

fouedmoussi avatar Dec 03 '19 07:12 fouedmoussi

Please review this pull request

maherelgamil avatar Feb 06 '20 13:02 maherelgamil

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.

m2de avatar Feb 07 '20 11:02 m2de

Is it possible to merge this pull request?

StanMenten-bp avatar Dec 16 '21 11:12 StanMenten-bp