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');
});
}
)
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;
// ...
}