PHP code example of think.studio / nova-page-settings
1. Go to this page and download the library: Download think.studio/nova-page-settings 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/ */
think.studio / nova-page-settings example snippets
public function up() {
Schema::create( config('nova-page-settings.default.settings_table'), function ( Blueprint $table ) {
\Thinkone\NovaPageSettings\MigrationHelper::defaultColumns($table);
} );
}
namespace App\Nova\Resources;
class PageSettingResource extends Resource
{
use \Thinkone\NovaPageSettings\Nova\Resources\Traits\AsPageSetting;
public static $model = \Thinkone\NovaPageSettings\Adapters\CMSPageSettingModel::class;
public static $searchable = false;
public static $globallySearchable = false;
public static $title = \Thinkone\NovaPageSettings\QueryAdapter\InternalSettingsModel::ATTR_NAME;
public static $perPageOptions = [ 1000 ];
public static function label()
{
return 'Custom settings';
}
public static function uriKey()
{
return 'custom-page-settings';
}
}
namespace App\Nova\PageSettings\Templates;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Http\Requests\NovaRequest;
use Thinkone\NovaPageSettings\Templates\BaseTemplate;
use NovaFlexibleContent\Flexible;
class MarketingPageSettings extends BaseTemplate
{
public function fields(NovaRequest $request)
{
return [
// NOTICE: do not forget use "templateKey" method
Email::make('Notification email', $this->templateKey('notification_email'));
Flexible::make('Slider', $this->templateKey('slider'))
->addLayout('Custom Slide', 'custom_slide', [
Text::make('Title', 'title'),
Textarea::make('Text', 'text'),
Text::make('Button Text', 'btn_text'),
Text::make('Button Link', 'btn_link'),
])
->limit(4)
->button('Add Slide'),
// ... other fields
];
}
}
/** @var \Illuminate\Support\PageSettingsCollection $pageSettings */
$pageSettings = MarketingPageSettings::retrieve();
// get array of slides using helper
$slides = $pageSettings->getSettingValue( 'slider', 'array', []);
// get typed value
$slides = $pageSettings->arraySettingValue( 'slider', []);
$slides = $pageSettings->stringSettingValue( 'notification_email');
// or
/** @var array $viewData */
$viewData = MarketingPageSettings::viewData();
echo $viewData['slider'];
namespace App\Models;
class PageSetting extends \Thinkone\NovaPageSettings\Model\PageSetting
{
use \NovaFlexibleContent\Concerns\HasFlexible;
public function valueFlexible(array $layoutMapping = []): \NovaFlexibleContent\Layouts\LayoutsCollection
{
return $this->flexible('value', $layoutMapping);
}
}