• Stars
    star
    279
  • Rank 143,276 (Top 3 %)
  • Language
    PHP
  • License
    Other
  • Created about 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Administer presentation pages in Laravel, using page templates and Backpack\CRUD

BackPack\PageManager

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

An interface to let your admins add and edit presentation pages to your Laravel 6, 7, 8, 9 or 10 website, by defining page templates with any number of content areas and any number of content types. Uses Laravel Backpack.

Backpack PageManager edit page

Security updates and breaking changes

Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.

Install

  1. Add a file to define your page templates in app/PageTemplates.php:
<?php

namespace App;

trait PageTemplates
{
    /*
    |--------------------------------------------------------------------------
    | Page Templates for Backpack\PageManager
    |--------------------------------------------------------------------------
    |
    | Each page template has its own method, that define what fields should show up using the Backpack\CRUD API.
    | Use snake_case for naming and PageManager will make sure it looks pretty in the create/update form
    | template dropdown.
    |
    | Any fields defined here will show up after the standard page fields:
    | - select template
    | - page name (only seen by admins)
    | - page title
    | - page slug
    */

    private function services()
    {
        $this->crud->addField([   // CustomHTML
                        'name' => 'metas_separator',
                        'type' => 'custom_html',
                        'value' => '<br><h2>'.trans('backpack::pagemanager.metas').'</h2><hr>',
                    ]);
        $this->crud->addField([
                        'name' => 'meta_title',
                        'label' => trans('backpack::pagemanager.meta_title'),
                        'fake' => true,
                        'store_in' => 'extras',
                    ]);
        $this->crud->addField([
                        'name' => 'meta_description',
                        'label' => trans('backpack::pagemanager.meta_description'),
                        'fake' => true,
                        'store_in' => 'extras',
                    ]);
        $this->crud->addField([
                        'name' => 'meta_keywords',
                        'type' => 'textarea',
                        'label' => trans('backpack::pagemanager.meta_keywords'),
                        'fake' => true,
                        'store_in' => 'extras',
                    ]);
        $this->crud->addField([   // CustomHTML
                        'name' => 'content_separator',
                        'type' => 'custom_html',
                        'value' => '<br><h2>'.trans('backpack::pagemanager.content').'</h2><hr>',
                    ]);
        $this->crud->addField([
                        'name' => 'content',
                        'label' => trans('backpack::pagemanager.content'),
                        'type' => 'summernote',
                        'placeholder' => trans('backpack::pagemanager.content_placeholder'),
                    ]);
    }

    private function about_us()
    {
        $this->crud->addField([
                        'name' => 'content',
                        'label' => trans('backpack::pagemanager.content'),
                        'type' => 'summernote',
                        'placeholder' => trans('backpack::pagemanager.content_placeholder'),
                    ]);
    }
}
  1. In your terminal
composer require backpack/pagemanager
  1. Publish the views, migrations and the PageTemplates trait:
php artisan vendor:publish --provider="Backpack\PageManager\PageManagerServiceProvider"
  1. Run the migration to have the database table we need:
php artisan migrate
  1. [optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:
php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-link' href='{{ backpack_url('page') }}'><i class='nav-icon la la-file-o'></i> <span>Pages</span></a></li>"

Usage

  1. Go to yourapp/admin/page and see how it works.
  2. Define your own templates in app/PageTemplates.php using the Backpack\CRUD API.

Example front-end

No front-end is provided (Backpack only takes care of the admin panel), but for most projects this front-end code will be all you need:

(1) Create a catch-all route at the end of your routes file:

/** CATCH-ALL ROUTE for Backpack/PageManager - needs to be at the end of your routes.php file  **/
Route::get('{page}/{subs?}', ['uses' => '\App\Http\Controllers\PageController@index'])
    ->where(['page' => '^(((?=(?!admin))(?=(?!\/)).))*$', 'subs' => '.*']);

(2) Create app\Http\Controllers\PageController.php that actually shows the page.

<?php

namespace App\Http\Controllers;

use Backpack\PageManager\app\Models\Page;
use App\Http\Controllers\Controller;

class PageController extends Controller
{
    public function index($slug, $subs = null)
    {
        $page = Page::findBySlug($slug);

        if (!$page)
        {
            abort(404, 'Please go back to our <a href="'.url('').'">homepage</a>.');
        }

        $this->data['title'] = $page->title;
        $this->data['page'] = $page->withFakes();

        return view('pages.'.$page->template, $this->data);
    }
}

(3) Create the views for those templates (how those pages actually look - the HTML CSS JS) and place them in your resources/views/pages/ directory. Inside those blade files, you can use the $page variable. That's where all the page content is stored. For more complicated pages, you can also use fake fields in your page templates. You'll also find those attributes in the $page variable.

Note: if you find yourself in need of sending extra data to a view you load on multiple pages, you should consider using a view composer;

Extend

If you need to make any modifications to the controller, model or request, you should:

  • make sure config/backpack/pagemanager.php is published; if not, publish it using php artisan vendor:publish --provider="Backpack\PageManager\PageManagerServiceProvider";
  • create a new controller/model that extends the one in the package;
  • enter controller or model in the pagemanager.php config file, and that's the one that the CRUD will be using;

Optional: Mutator for fields using 'store_in' and 'fake' keys

Fake fields do not trigger individual mutators, they trigger the "fake column" mutator. For example instead of defining a setImageAttribute() mutator, please define a setExtrasAttribute() mutator. You'll have the $value then.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Overwriting Functionality

If you need to modify how this works in a project:

  • create a routes/backpack/pagemanager.php file; the package will see that, and load your routes file, instead of the one in the package;
  • create controllers/models that extend the ones in the package, and use those in your new routes file;
  • modify anything you'd like in the new controllers/models;

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

Backpack is free for non-commercial use and 69 EUR/project for commercial use. Please see License File and backpackforlaravel.com for more information.

Hire us

We've spend more than 10.000 hours creating, polishing and maintaining administration panels on Laravel. We've developed e-Commerce, e-Learning, ERPs, social networks, payment gateways and much more. We've worked on admin panels so much, that we've created one of the most popular software in its niche - just from making public what was repetitive in our projects.

If you are looking for a developer/team to help you build an admin panel on Laravel, look no further. You'll have a difficult time finding someone with more experience & enthusiasm for this. This is what we do. Contact us - let's see if we can work together.

More Repositories

1

CRUD

Build custom admin panels. Fast!
PHP
2,816
star
2

Base

Until 2018, Backpack v3 used this Base package to offer admin authentication and a blank admin panel using AdminLTE. Backpack v4 no longer uses this package, they're now built-in - use Backpack/CRUD instead.
PHP
891
star
3

PermissionManager

Admin interface for managing users, roles, permissions, using Backpack CRUD
PHP
481
star
4

BackupManager

Admin interface for managing database and file backups in Backpack for Laravel
PHP
305
star
5

demo

A working demo of Laravel with all Backpack packages installed.
PHP
301
star
6

Generators

Generate files for Backpack projects
PHP
296
star
7

LogManager

An interface to preview, download and delete Laravel log files, using Backpack.
PHP
261
star
8

Settings

Application settings interface for Backpack (for Laravel 6).
PHP
228
star
9

NewsCRUD

An admin panel for news with categories and tags, using Backpack CRUD on Laravel 10
PHP
205
star
10

MenuCRUD

An admin panel for menu items, using Backpack\CRUD on Laravel 6 or 7.
Blade
182
star
11

LangFileManager

A quick interface to edit Laravel language files, for Backpack.
PHP
90
star
12

FileManager

Admin interface for files & folders, using elFinder.
PHP
79
star
13

docs

45
star
14

revise-operation

An admin interface for venturecraft/revisionable - audit log for your Eloquent entries.
PHP
42
star
15

basset

Better asset helpers for Laravel apps.
PHP
36
star
16

community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
25
star
17

theme-tabler

UI for Backpack v6 that uses Tabler and Bootstrap v5.
Blade
16
star
18

activity-log

PHP
13
star
19

download-operation

PHP
10
star
20

medialibrary-uploaders

PHP
8
star
21

language-switcher

Multi language dropdown for Backpack v6
PHP
7
star
22

addons

A place for the Backpack community to talk about possible Backpack add-ons.
5
star
23

theme-coreuiv2

UI that uses CoreUI v2 and Bootstrap v4, provided as a legacy theme for Backpack v6.
Blade
4
star
24

theme-coreuiv4

UI for Backpack v6 that uses CoreUI v4 and Bootstrap v5.
Blade
3
star
25

devtools-issues

Bug reports and feature requests for our closed-source DevTools package
3
star
26

legal-documents

All legal documents for the Backpack organisation. Full transparency.
1
star