PHP code example of lupennat / nova-expandable-many

1. Go to this page and download the library: Download lupennat/nova-expandable-many library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lupennat / nova-expandable-many example snippets



use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Http\Requests\NovaRequest;

class User extends Resource
{

   use Lupennat\ExpandableMany\HasExpandableMany;

    public function fields(Request $request)
    {
        return [
            HasMany::make('User Post', 'posts', Post::class)->expandable();
        ];
    }
}

    HasMany::make('User Post', 'posts', Post::class)->expandable()
        ->withMeta([
            'expandableShowLabel' => 'Custom Show',
            'expandableHideLabel' => 'Custom Hide',
        ])

    HasMany::make('User Post', 'posts', Post::class)->expandable()
        ->withMeta([
            'expandableShowHtml' => '<strong>Custom Show Html</strong>',
            'expandableHideHtml' => '<strong>Custom Hide Html</strong>',
        ])

    HasMany::make('User Post', 'posts', Post::class)->expandable()
        ->withMeta([
            // 'expandableStoreStatus' => 'full', // will store status also for relationships
            'expandableStoreStatus' => 'accordion', // will store status only for accordion
            'expandableStoreStatus' => '', // will not store any status
        ])

    HasMany::make('User Post', 'posts', Post::class)->expandable()
        ->withMeta([
            'expandableSkip' => true,
            'expandableSkipLabel' => '', // default is '—'
        ])

    HasMany::make('User Post', 'posts', Post::class)->expandable()
        ->withMeta([
            'expandableUseStandardActions' => false, // disable create/edit/view/delete/restore
        ])

    HasMany::make('User Post', 'posts', Post::class)
        ->expandable(function(HasMany $field, $resource) {
            $resource->loadCount('posts');
            $field->withMeta([
                'expandableShowLabel' => 'Show ' . $resource->posts_count,
                'expandableSkip' => $resource->posts_count === 0
            ]);
        })


use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Lenses\Lens;

class UserLens extends Lens
{
   use Lupennat\ExpandableMany\HasExpandableManyLens;

    public function fields(Request $request)
    {
        return [
            HasMany::make('User Post', 'posts', Post::class)->expandable();
        ];
    }
}