novius/laravel-nova-visual-composer
Composer 安装命令:
composer require novius/laravel-nova-visual-composer
包简介
A Laravel Nova field to compose blocks.
README 文档
README
Requirements
- PHP >= 7.4
- Laravel Framework >= 8.
- Nova >= 2.0
- Imagick PHP extension or GD Library (for Intervention Image)
NOTE: These instructions are for Laravel >= 8. If you are using prior version, please see the previous version's docs.
Installation
composer require novius/laravel-nova-visual-composer
Next, configure Intervention Image package :
Intervention Image configuration instructions
Configuration
Some options that you can override are available.
php artisan vendor:publish --provider="Novius\NovaVisualComposer\NovaVisualComposerServiceProvider" --tag="config"
JS Configuration
Some options (like wysiwyg config) are configurable from JS config file.
You can override it with :
php artisan vendor:publish --provider="Novius\NovaVisualComposer\NovaVisualComposerServiceProvider" --tag="js"
Purge TMP uploaded files
In your app/Console/Kernel.php file, you should register a daily job to purge any stale files :
protected function schedule(Schedule $schedule) { $schedule->command('nova-visual-composer:purge-tmp-files') ->daily(); }
By default tmp file is stale considered after 24h. You can override this value in configuration file with seconds_before_purge_tmp_files key.
Usage
Step 1
Create a long text column on your model's table.
$table->longText('content')->nullable();
Configure your model by adding object to the desired column.
use Illuminate\Database\Eloquent\Model; class Foo extends Model { protected $casts = [ 'content' => 'object', ]; }
Step 2
Add the field to your Nova resource.
use App\Nova\Resource; use Novius\NovaVisualComposer\NovaVisualComposer; class FooResource extends Resource { public function fields(Request $request) { return [ // .. NovaVisualComposer::make('Content') ->stacked(), // .. ]; } }
Step 3
Display in your blade template.
@foreach($item->content as $row) {!! $row->template::renderFront($row->content) !!} @endforeach
Create new row templates
Step 1
You have to publish lang and view files.
php artisan vendor:publish --provider="Novius\NovaVisualComposer\NovaVisualComposerServiceProvider" --tag="config" php artisan vendor:publish --provider="Novius\NovaVisualComposer\NovaVisualComposerServiceProvider" --tag="views"
Step 2
Create your own Row Template and link it into configuration file.
Row Template Class
namespace App\Nova\Templates\Rows; use Novius\NovaVisualComposer\Templates\RowTemplateAbstract; use Novius\NovaVisualComposer\Traits\HasImageField; use Novius\NovaVisualComposer\Traits\HasPrunableFiles; class ImageText extends RowTemplateAbstract { use HasImageField; use HasPrunableFiles; public static $name = 'image-text'; protected static function imageFieldsIndexes(): array { return [0]; // Because image field is the first field that contains "js-visual-field" class of CRUD view } }
Add it to configuration file
return [ ... 'templates' => [ \Novius\NovaVisualComposer\Templates\Article::class, \Novius\NovaVisualComposer\Templates\ImageMultiple::class, \Novius\NovaVisualComposer\Templates\ImageSimple::class, \Novius\NovaVisualComposer\Templates\Separator::class, \Novius\NovaVisualComposer\Templates\Title::class, // Custom Template \App\Nova\Templates\Rows\ImageText::class, ], ];
Step 3
Create template views (CRUD + front views).
resources/views/vendor/nova-visual-composer/templates/ImageText/crud.blade.php
TIPS :
- Each HTML field that you want to save must contains
js-visual-fieldclass. - If you want a wysiwyg add
js-wysiwygclass to textarea field. - If you want an image upload field add
js-image-uploaderclass to file field. - If you want a multiple images upload field add
js-image-uploaderclass +multipleattribute to file field.
<div class="shadow-md mb-4 w-full"> <div class="px-6 py-4"> <div class="font-bold text-xl mb-4"> {{ $templateDetails['name_trans'] }} </div> <div class="flex"> <div class="w-1/3 pr-3"> <div class="form-group"> <input type="file" class="filepond js-visual-field js-image-uploader"> </div> </div> <div class="w-2/3"> <div class="form-group mb-2"> <label class="block text-grey-darker text-sm font-bold mb-2"> {{ trans('nova-visual-composer::templates.'.$templateName.'.crud_pre_title') }} </label> <input class="js-visual-field w-full form-control form-input form-input-bordered" type="text"/> </div> <div class="form-group mb-2"> <label class="block text-grey-darker text-sm font-bold mb-2"> {{ trans('nova-visual-composer::templates.'.$templateName.'.crud_title') }} </label> <input class="js-visual-field w-full form-control form-input form-input-bordered" type="text"/> </div> <div class="form-group mb-2"> <label class="block text-grey-darker text-sm font-bold mb-2"> {{ trans('nova-visual-composer::templates.'.$templateName.'.crud_text') }} </label> <textarea name="content" class="js-visual-field js-wysiwyg w-full form-control form-input-bordered py-2 h-20"></textarea> </div> </div> </div> </div> </div>
resources/views/vendor/nova-visual-composer/templates/ImageText/front.blade.php
@php if (empty($content) || !is_array($content)) { return; } list( $images, $preTitle, $title, $htmlContent, ) = $content; $image = is_array($images) ? array_shift($images) : null; @endphp <div class="block-image-text"> @if (!empty($image)) <img src="{{ asset('storage/'.$image) }}"/> @endif @if (!empty($preTitle)) <h5 class="pre-title"> {{ $preTitle }} </h5> @endif @if (!empty($title)) <h3 class="title"> {{ $title }} </h3> @endif @if (!empty($htmlContent)) <div class="content"> {!! $htmlContent !!} </div> @endif </div>
Step 4
Add your translations to language files.
resources/lang/vendor/nova-visual-composer/fr/templates.php
return [ ... 'image-text' => [ 'name' => 'Image / texte', 'crud_pre_title' => 'Sur-titre', 'crud_title' => 'Titre', 'crud_text' => 'Texte', ], ];
Lint
Run php-cs with:
composer run-script lint
Contributing
Contributions are welcome! Leave an issue on Github, or create a Pull Request.
Licence
This package is under GNU Affero General Public License v3 or (at your option) any later version.
novius/laravel-nova-visual-composer 适用场景与选型建议
novius/laravel-nova-visual-composer 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 28.21k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2019 年 09 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 novius/laravel-nova-visual-composer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 novius/laravel-nova-visual-composer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 novius/laravel-nova-visual-composer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
A Laravel Nova Image field. you can paste or drag or chose an image
A Laravel Nova Mail testing tool.
统计信息
- 总下载量: 28.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2019-09-11