Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow displaying nested checkboxes #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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