clevyr/backpack-page-builder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

clevyr/backpack-page-builder

最新稳定版本:v3.2.1

Composer 安装命令:

composer require clevyr/backpack-page-builder

包简介

Clevyr Page Builder for Backpack

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Prerequisite

Laravel Backpack must be installed

  1. Laravel 7
  2. PHP 7.4
  3. GD or Imagick for Image Intervention

Table of Contents

Installation

Run composer require clevyr/backpack-page-builder

This will install the Page Builder and the https://github.com/Laravel-Backpack/PermissionManager package

This will install Image Intervention http://image.intervention.io/getting_started/introduction

To install the Page builder run the following command, this will install the Permissions Manager and the Page Builder

Run php artisan pagebuilder:install

Update the config -> backpack -> base.php file

'guard' => 'backback',

to

'guard' => config('auth.defaults.guard'),

Run composer dump-autoload

Seed the permissions

Run php artisan db:seed --class=PageBuilderSeeder

Update resources -> views -> vendor -> backpack -> base -> inc -> sidebar_content.blade.php file with

@canany(['View User List', 'View Role List', 'View Permission List'])
    <li class="nav-item nav-dropdown">
        <a class="nav-link nav-dropdown-toggle" href="#"><i class="nav-icon la la-users"></i> Authentication</a>

        <ul class="nav-dropdown-items">
            @can('View User List')
                <li class="nav-item"><a class="nav-link" href="{{ backpack_url('user') }}"><i class="nav-icon la la-user"></i> <span>Users</span></a></li>
            @endcan

            @can('View Role List')
            <li class="nav-item"><a class="nav-link" href="{{ backpack_url('role') }}"><i class="nav-icon la la-id-badge"></i> <span>Roles</span></a></li>
            @endcan

            @can('View Permission List')
                <li class="nav-item"><a class="nav-link" href="{{ backpack_url('permission') }}"><i class="nav-icon la la-key"></i> <span>Permissions</span></a></li>
            @endcan
        </ul>
    </li>
@endcanany

@can('View Page List')
    <li class="nav-item nav-dropdown">
        <a class="nav-link nav-dropdown-toggle" href="#">
            <i class="nav-icon la la-folder"></i>
            Pages
        </a>

        <ul class="nav-dropdown-items">
            <li class="nav-item">
                <a class="nav-link" href="{{ backpack_url('pages') }}">
                    <i class="nav-icon la la-address-book"></i>

                    <span>
                        Manage
                    </span>
                </a>
            </li>
        </ul>
    </li>
@endcan

Update app -> User.php with

...
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Spatie\Permission\Traits\HasRoles;
...

class User extends Model {
    ...
    use CrudTrait;
    use HasRoles;
    ...
}

Create a super admin

Run php artisan pagebuilder:user

Run with parameters

php artisan pagebuilder:user --name=Name --email=email@example.com --password=password

Page Development

Syncing pages

Navigate to pages -> manage

Click the sync icon in the bottom right, this will load in static pages (Every folder that is not the dynamic folder) and it will reload the page

You also have the option to sync them from the command line with the following command

php artisan pagebuilder:sync

Editing static pages

Navigate to the page management page and click edit on the homepage

Page Settings

Name: Page name, admin functionality only, does not affect the functionality of the page's at all

Title: Page title, also generates the slug as you type

Slug: Slug of the page

View: Page view

Page Content

The page content populates with a list of sections, and their fields which you can edit.

Editing Dynamic pages

See Editing Static Pages for a run down of Page Settings and Page Content

  • Page Layout

Note - You can only use the Page Layout tab if you are working with a dynamic page

Sections list

A list of dynamic sections will be displayed, you can click them to add them to the Content Section

Content Section

The content section displays the sections that will be available to edit on the page

You will not be able to edit the content until you save the page

Creating pages

Pages are located at resources -> views -> pages each folder is considered as the page, with the contents inside the folder dictating what view / sections are available

Contents

  • Sections - Holds each individual section for that view
  • config.php - Holds the configuration for the page sections
  • index.blade.php - Is the view of the page

Note - Pages sections will not sync if there is not a .blade file inside the sections directory and a config property inside the config.php

Generating Pages

To generate a new page run the following command php artisan pagebuilder:page page with page being the name of the new page

This will create a folder with the page name with the following structure

  • page
    • index.blade.php
    • config.php
    • sections
      • default.blade.php

Sections

The sections folder holds the .blade files that correspond to the section key in the config.php

Using data inside a section

You have access to the $sections variable which is an anonymous function that returns the field data from the section name and the field title

<h1>
    {{-- default: section name, title: field name --}}
    {{ $sections('default', 'title') }}

    <br />

    <small>
        {{ $sections('default', 'sub-title') }}
    </small>
</h1>

{!! $sections('default', 'content') !!}

config.php

The config.php holds the configuration of the page sections. Each section holds a list of backpack crud fields https://backpackforlaravel.com/docs/4.1/crud-fields any field, including custom fields will be available to be used inside the config.

Example config

<?php

return [
    'default' => [ // Section name, the blade file for the section's name must be the same as this key
        'is_dynamic' => true, // Defaults to false, if this is set it will be available to be used in dynamic pages
        'title' => [ // Field name
            'type' => 'text', // crud field type
            'name' => 'title', // crud field name
            'label' => 'Title' // crud field label
            // ... Any other crud field properties
        ],
        'sub-title' => [
            'type' => 'text',
            'name' => 'sub-title',
            'label' => 'Sub Title'
        ],
        'content' => [
            'type' => 'wysiwyg',
            'label' => 'Content',
            'name' => 'content',
        ],
    ],
];

index.blade.php

The index.blade.php is the view file for the page and it's sections.

Example index.blade.php

<div>
    @include('pages.homepage.sections.default')
</div>

Development

Submitting Changes

Please push your changes to a new branch before submitting a PR

Setting up local package development

  1. Within the root of an existing Laravel Backpack project, clone this project to ./packages/clevyr/backpack-page-builder
  2. Add the following to your composer.json
"repositories": [
    {
        "type": "path",
        "url": "./packages/clevyr/backpack-page-builder",
        "options": {
            "symlink": true
        }
    }
],
  1. Add clevyr/backpack-page-builder to your list of requires in your composer.json like below:
"require": {
...
"clevyr/backpack-page-builder": "dev-master",
...
}
  1. Run composer require clevyr/backpack-page-builder

clevyr/backpack-page-builder 适用场景与选型建议

clevyr/backpack-page-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2020 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「addon」 「laravel」 「admin panel」 「toggle」 「backpack」 「Backpack for Laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 clevyr/backpack-page-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 clevyr/backpack-page-builder 我们能提供哪些服务?
定制开发 / 二次开发

基于 clevyr/backpack-page-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 16
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-07-01