dewsign / nova-pages
Pages module for Laravel Nova
Installs: 656
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 3
Forks: 5
Open Issues: 2
Type:package
Requires
- php: >=7.0.0
- benjaminhirsch/nova-slug-field: ^1.0
- dewsign/nova-repeater-blocks: ^1.2.0
- epartment/nova-dependency-container: ^1.1
- laravel/framework: >=5.0.0
- maxfactor/support: ^2.0.0
- rinvex/countries: ^6.1
- silvanite/brandenburg: ^1.0
- silvanite/novatoolpermissions: ^1.1
Requires (Dev)
- squizlabs/php_codesniffer: >=3.1
- dev-master
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-fix-no-dev
- dev-task-search-improvements
- dev-task-image-alts
- dev-task-private-access
- dev-task-image-video
- dev-task-docs
- dev-task-domain-map-routing
- dev-fix-duplicate-homepages
- dev-fix-seeding
- dev-fix-incorrect-config
- dev-fix-sitemap
- dev-fix-reademe
- dev-task-routing
- dev-fix-seeder-pageclass
- dev-task-domain-map
- dev-task-decouple
- dev-task-scout-optional
- dev-image-sizing-in-config
- dev-adjust-image-size
- dev-task-searchable
- dev-fix-priority-cannot-null
This package is auto-updated.
Last update: 2024-11-07 21:52:00 UTC
README
Easily create custom pages in Nova using repeaters blocks for content. See documentation for Repeater Blocks for details.
Pages can be nested (as many levels deep as required), e.g. /page-one/page-two/page-three/page-four
and a page can have any number of child pages.
Even though this package does not provide any kind of layout or design, the Page model makes use of various traits and base model of the Maxfactor Laravel Support package to provide a lot of common functionality typically expected with public facing web pages, including Search Engine Optimisation (SEO). See the Maxfactor Laravel Support repo for more information.
Installation
composer require dewsign/nova-pages
Run the migrations
php artisan migrate
Load the tool in your NovaServiceProvider.php
public function tools() { return [ ... new \Dewsign\NovaPages\Nova\NovaPagesTool, ... ]; }
Default Fields
Using the provided scopes makes for a nice fluent API to lookup pages.
E.g. Page::active()->featured()->highToLow()->take(3)->get()
.
Templates
The packages doesn't come with any pre-made templates. Simply replace the published resources/views/vendor/nova-pages/show.blade.php
view or create new templates inside the resources/views/vendor/nova-pages/templates
folder. When more than one template exists, a select option will be displayed within nova where you can select the template for the page.
Configuration
Repeaters
Nova Pages will use the Repeater Blocks defined in the Nova Repeater Blocks package config by default and you can add additional repeater blocks by adding them to the nova-pages config file.
'repeaters' => [ 'More\Repeaters' ],
Alternatively you can remove all standard repeaters and use your own selection.
'replaceRepeaters' => true,
Homepage / Default page
You can define which page slug should be loaded as the homepage, accessible at /
, unless you already have a custom route defined, in which case Nova Pages will not assign the homepage route!
In the below example, creating a Page with the homepage
slug will be served as the default page when accessing the website.
'homepageSlug' => 'homepage',
Customisation
If you want more control, you can specify which Nova Resource and Page model to use. Because of the way nova reads the model from a static variable you must provide your own custom resource if you want to use a custom model.
In all cases, these should extend the default Page models and resource in this package.
'models' => [ 'page' => 'App\Page', ], 'resources' => [ 'page' => 'App\Nova\Page', ],
Nova Resource Group
'group' => 'Pages',
You can customise where you want the Pages resource to appear inside Laravel Nova. By default it will sit all by itself in a Pages section.
Routing
This package makes use of a catch-all route, so any url not caught by the applications web routes will be captured and processed to find a page matching the slug. This allows us to make all pages are accessible without any specific prefix.
A 404 error will be thrown if no matching page was found.
Factories & Seeders
The package comes with pre-made factories and seeders. Should you wish to include them in your application simply call the seeder or use the factory provided to populate your database with some sample content.
// database/seeds/DatabaseSeeder.php public function run() { $this->call(Dewsign\NovaPages\Database\Seeds\PageSeeder::class); }
Domain Maps
You can map sub-domains (e.g. careers.mydomain.com) to Pages to automatically serve pages matching the base slug, and any child pages, on this domain. Any number of sub-domains are supported by adding the slugs to the domainMap
array in the configuration file.
Important: If you are using domain maps, you must set the rootDomain
in your config or provided env lookup for ROOT_DOMAIN
. E.g. mydomain.com
.
return [ ... 'domainMap' => [ 'careers', ], ];
Int he above example, if you create a Page with the careers
slug, this and any sub-pages will be served on the sub-domain with the base slug removed. E.g. mydomain.com/careers/vacancies
will become careers.mydomain.com/vacancies
.
Important: You will need to ensure that any non-page routes go to the the correct domain name. We recommend always routing to full URLs rather than relative path.
We provide two route helpers, you can safely use the pages.show
route name if you are not using domain maps at all. If you are using domain maps, you can use the domain.pages.show
helper which accepts an additional domain parameter.
route('pages.show', ['path' => 'careers']); // https://mydomain.com/careers route('domain.pages.show', ['domain' => 'careers', 'path' => 'vacancies']); // https://careers.mydomain.com/vacancies
Permissions
A PagePolicy is included, but not loaded by default, for the Nova Permissions Tool, which uses Brandenburg under the hood. Simply load the AuthServiceProvider from this package to make use of this or ignore this if you are using an alternative permissions library.
// config/app.php 'providers' => [ ... Dewsign\NovaPages\Providers\AuthServiceProvider::class, ],
Helpers
Meta pages
When working with sections of your application which are routed to their own controllers you may still want to allow users to add additional content and manage meta information through the UI. You can include the provided meta
helper to retrieve this meta data from Pages.
$page = Page::meta('page-slug', 'Default Text');
Will return the Page model if a matching page is found, otherwise will return an array with defaults ...
[ 'page_title' => 'Default Text', 'browser_title' => 'Default Text', 'meta_description' => 'Default Text', 'h1' => 'Default Text', ];
Use the meta page to provide this content to the front-end means you can re-use a lot of code across all sections of your site to keep things consistent and benefit from the included SEO value.
Language
You are able to change what html lang type the page will be on creation. You can enable this functionality by setting the enableLanguageSelection
config value to true
;
To implement this into your markup, we suggest adding this to your layouts.default
view:
<html lang="{{ array_get($page ?? [], 'language', app()->getLocale()) }}">
There is a defaultLanguage
config variable that you are free to customise to suit your application. This package comes with en-GB
set as the default language.
Access Control
This package makes use of silvanite/novatoolpermissions to handle access control to pages. Please refer to the documentation for novatoolpermissions
for more info.
The function authoriseToView
on the Page
model can be overridden to customise the access control functionality. Alternatively, use the accessContent
gate in the PagePolicy.