PHP code example of esign / nova-flexible

1. Go to this page and download the library: Download esign/nova-flexible 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/ */

    

esign / nova-flexible example snippets


class Page extends Resource
{
	use \Marshmallow\Nova\Flexible\Nova\Traits\HasFlexable;

	public function fields(Request $request)
	{
		return [
			// ...
			$this->getFlex(),
			// ...
		];
	}
}

class Page extends Model
{
	use \Marshmallow\Nova\Flexible\Concerns\HasFlexible;

	protected $casts = [
		/**
		 * 'layout' in the example below references the field
		 * in the model where the json is stored.
		 */
		'layout' => \Marshmallow\Nova\Flexible\Casts\FlexibleCast::class,
	];
}

// Layout class
// In a layout class you just set the $titleFromContent property to the field name you
// wish it shows.
protected $titleFromContent = 'title';

/**
 * For custom layout, we need to add a 4th parameter. This should be a callable and call the setTitleFromContent method.
 */
->addLayout(
	'Mr. Mallow',
	'mr_mallow', [
        Text::make('Title', 'title'),
        Text::make('Sub title', 'sub_title'),
        // ...
	],
	function ($layout) {
		return $layout->setTitleFromContent('sub_title');
    }
)


/**
 * You can also use a callback to build your title.
 */
->addLayout(
	'Mr. Mallow',
	'mr_mallow', [
        Text::make('Title', 'title'),
        Date::make('Date', 'date'),
        Textarea::make('Content', 'content'),
        // ...
	],
	function ($layout) {
		return $layout->resolveTitleUsing(function ($title, $date, $content) {
            return $title . ' ' . Carbon::parse($date)->format('Y-m-d');
        });
    }
)

$this->getFlex(__('Layout'), 'layout')
    ->loadConfig([
        'simpleView' => null,
        'allowedToCreate' => ['allowed' => true|false],
        'allowedToDelete' => ['allowed' => true|false],
        'allowedToChangeOrder' => ['allowed' => true|false],
        'simpleMenu' => null,
        'button' => ['label' => 'Button Label'],
        'fullWidth' => ['fullWidth' => true|false],
        'limit' => ['limit' => 3],
    ]),

Flexible::make(__('Marshmallow'), 'marshmallow')
    ->addLayout(__('Mr. Mallow'), 'mr_mallow', [
        //
    ])

    // Don't use the component selector but a simple dropdown menu
    ->simpleMenu()

    // Use the full with of the nova container
    ->fullWidth()

    // Collapse all layouts when they are loaded
    ->collapsed()

    // Change the text in the add more layouts button
    ->button(__('Add comment'))

    // Disable deleting items
    ->deletionNotAllowed();

namespace App\Nova\Templates;

// ...
use Marshmallow\Nova\Flexible\Concerns\HasFlexible;

class Home extends Template
{
    use HasFlexible;

    // ...
}
bash
php artisan make:flex Element\\Counter --livewire
bash
php artisan make:flex Forms\\Newsletter --template=newsletter
php artisan make:flex Forms\\Contact --template=form