承接 think.studio/nova-page-settings 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

think.studio/nova-page-settings

最新稳定版本:4.4.0

Composer 安装命令:

composer require think.studio/nova-page-settings

包简介

Ad hoc solution to add settings configuration to laravel nova

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Ad hoc solution to add settings configuration to laravel nova.

Nova Package
V1 V1, V2
V4 V3, V4

Installation

You can install the package via composer:

composer require think.studio/nova-page-settings

Optional publish configs

php artisan vendor:publish --provider="ThinkOne\NovaPageSettings\ServiceProvider" --tag="config"

Usage

Admin part

  1. Create settings table (migration)
public function up() {
    Schema::create( config('nova-page-settings.default.settings_table'), function ( Blueprint $table ) {
        \Thinkone\NovaPageSettings\MigrationHelper::defaultColumns($table);
    } );
}
  1. Create resource
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';
    }
}
  1. Create templates in folder what you specified in step 3. System will find all templates in folder automatically.
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
        ];
    }
}
  1. As a result, you should see something like this:

Frontend part

 /** @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'];

Use flexible

If you need to use flexible content package you will need override default model:

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);
    }
}

Credits

  • Think Studio

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-28