Easily add routes to your Laravel app by creating Markdown or Blade files

Overview

Laravel Pages

This package lets you create pages using Markdown or Blade without having to worry about creating routes or controllers yourself.

Essentially, you create either content/pages/foo.md or resources/views/pages/foo.blade.php and the page will be accessible on the /foo route.

Markdown files use a pre-defined Blade view to get rendered. Blade files are meant for pages which don't follow the default layout and need more custom styling.

For instance, you could have the /pricing route use a Blade file (pages/pricing.blade.php) with a pretty design that accompanies your pricing copy.

Whereas for /about, you could have a simple Markdown file (content/pages/about.md) that describes your service using pure text without any special graphical elements.

We use this on the ArchTech website — the About, Careers, and Open Source pages are simple Markdown files.

Installation

Require the package via composer:

composer require archtechx/laravel-pages

Publish the config file:

php artisan vendor:publish --tag=archtech-pages-config

And finally, add this line to the end of your routes/web.php file:

ArchTech\Pages\Page::routes();

This line will register the routes in a way that ensures that your routes take precedence, and the page route is only used as the final option.

Important: Before attempting to visit URLs managed by this package, make sure that you configure it to use the correct layout (see the section below). Otherwise you might get an error saying that the view cannot be found.

Usage

Markdown pages

To create a markdown file, create a file in content/pages/. The route to the page will match the file name (without .md).

For example, to create the /about page, create content/pages/about.md with this content:

---
slug: about
title: 'About us'
updated_at: 2021-05-19T19:09:02+00:00
created_at: 2021-05-19T19:09:02+00:00
---

We are a web development agency that specializes in ...

Blade pages

To create a Blade page, create a file in resources/views/pages/. Like in the Markdown example, the route to the page will match the file name without the extension.

Therefore to create the /about page, you'd create resources/views/pages/about.blade.php:

<x-app-layout>
    This view can use any layouts or markup.
</x-app-layout>

Configuration

You'll likely want to configure a few things, most likely the used layout.

To do that, simply modify config/pages.php.

The config file lets you change:

  • the used model
  • the used controller
  • the layout used by the markdown views
  • the view file used to render Markdown pages
  • routing details

The layout is used by the vendor (package-provided) Markdown view. You'll likely want to set it to something like app-layout or layouts.app.

If you'd like to change the file that renders the Markdown itself, create resources/views/pages/_markdown.blade.php (the _ prefix is important as it prevents direct visits) and change the pages.views.markdown config key to pages._markdown.

And if you'd like to customize the routing logic more than the config file allows you, simply register the route yourself (instead of calling Page::routes()):

Route::get('/{page}', ArchTech\Pages\PageController::class);

Ecosystem support

The package perfectly supports other tools in the ecosystem, such as Laravel Nova or Lean Admin.

For example, in Laravel Nova you could create a resource for the package-provided Page model (ArchTech\Pages\Page) and use the following field schema:

public function fields(Request $request)
{
    return [
        Text::make('slug'),
        Text::make('title'),
        Markdown::make('content'),
    ];
}

Git integration & Orbit

This package uses Orbit under the hood — to manage the Markdown files as Eloquent models. If you'd like to customize some things related to that logic, take a look at the Orbit documentation.

The package also uses another package of ours, Laravel SEO, to provide meta tag support for Markdown pages. We recommended that you use this package yourself, since it will make handling meta tags as easy as adding the following line to your layout's <head> section:

<x-seo::meta />

Password-protected routes

The package also lets you protect certain routes with passwords. To add a password to a page, simply specify the password key in the YAML front matter:

password: 'foo'

Now if a user wants to visit the page, he will have to include ?password=foo in the URL, otherwise he'll be presented with a 403 error.

- /about
+ /about?password=foo
You might also like...
PHP Markdown Engine Support

PHP Markdown Version v1.x support all PHP version =5.4 v2.x support all PHP version =7.0 Cài đặt thư viện Thư viện này được cài đặt thông qua Compos

markdown wiki/blog
markdown wiki/blog

Kwiki markdown wiki/blog Usage Place your markdown files in the /wiki directory. Categories are directories and subcategories are subdirectories. If y

Rendering markdown from PHP code

JBZoo / Markdown Installing composer require jbzoo/markdown Usage Rendering Table ?php declare(strict_types=1); use JBZoo\Markdown\Table; echo (new

PHP Markdown & Extra

PHP Markdown & Extra An updated and stripped version of the original PHP Markdown by Michel Fortin. Works quite well with PSR-0 autoloaders and is Com

A simple regex-based Markdown parser in PHP

Slimdown A simple regex-based Markdown parser in PHP. Supports the following elements (and can be extended via Slimdown::add_rule()): Headers Links Bo

A super lightweight Markdown parser for PHP projects and applications.

A speedy Markdown parser for PHP applications. This is a super lightweight Markdown parser for PHP projects and applications. It has a rather verbose

PHP based Markdown documentation viewer

PHP based viewer for Markdown files, to view them with fenced code highlighting and navigation.

A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.

PHP Markdown PHP Markdown Lib 1.9.0 - 1 Dec 2019 by Michel Fortin https://michelf.ca/ based on Markdown by John Gruber https://daringfireball.net/ Int

Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.

PHP Markdown PHP Markdown Lib 1.9.0 - 1 Dec 2019 by Michel Fortin https://michelf.ca/ based on Markdown by John Gruber https://daringfireball.net/ Int

Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple
Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple

Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple

CodeIgniter4 Attribute Routes. You can set Routes in Controllers as PHP8 Attributes.

CodeIgniter4 Attribute Routes This package generates a Routes File from the Attribute Routes in your Controllers. You can set routes in your Controlle

🎌 Laravel Localization Helper :: Easily add translation variables from Blade templates.

LocalizationHelper Package for convenient work with Laravel's localization features and fast language files generation. Take a look at contributing.md

Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views
Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views

Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views. In all essence, it's a collection of useful utilities, connecting the dots between different parts of the TALL stack. It was made for Blade, Laravel's powerful templating engine.

A highly configurable markdown renderer and Blade component for Laravel
A highly configurable markdown renderer and Blade component for Laravel

A highly configurable markdown renderer and Blade component for Laravel This package contains: a Blade component that can render markdown a highly con

A Laravel package for creating a Markdown driven blog in minutes.

Static Markdown Blog A Laravel package for generating static blog posts from Markdown files. Sometimes, you want a blog but don't necessarily want to

Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline.

Blade Snip Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline: div class="products" @snip('pr

🍪 Write gorgeous documentation for your products using Markdown inside your Laravel app.
🍪 Write gorgeous documentation for your products using Markdown inside your Laravel app.

LaRecipe Write gorgeous documentations for your products using Markdown inside your Laravel app. LaRecipe 🍪 LaRecipe is simply a code-driven package

Custom Blade components to add sortable/drag-and-drop HTML elements in your apps.
Custom Blade components to add sortable/drag-and-drop HTML elements in your apps.

Laravel Blade Sortable Demo Repo Installation You can install the package via composer: composer require asantibanez/laravel-blade-sortable After the

Comments
  • Installation instructions not complete

    Installation instructions not complete

    Blade and markdown error after completing installation

    Unable to locate a class or view for component [app-layout]

    Follow the instructions below (you can copy paste the whole block) to create a bare install following the README.

    # Create bare laravel install
    
    composer create-project laravel/laravel archtechx-pages
    
    # cd into directory
    
    cd archtechx-pages
    
    # Add laravel-pages package
    
    composer require archtechx/laravel-pages
    
    # Publish config
    
    php artisan vendor:publish --tag=archtech-pages-config
    
    # Add Page::routes(); to routes/web.php
    
    echo "ArchTech\Pages\Page::routes();" >> routes/web.php
    
    # Create markdown directory and create about markdown page
    
    mkdir -p content/pages
    echo "---\nslug: about\ntitle: 'About us'\nupdated_at: 2021-05-19T19:09:02+00:00\ncreated_at: 2021-05-19T19:09:02+00:00\n---\n\nWe are a web development agency that specializes in ..." >> content/pages/about.md
    
    # Create blade directory and create test blade page
    
    mkdir -p resources/views/pages/
    echo "<x-app-layout>\nThis view can use any layouts or markup.\n</x-app-layout>" >> resources/views/pages/about.blade.php
    
    # Run clean up (for sanity reasons)
    
    php artisan cache:clear;php artisan config:clear;php artisan route:clear;php artisan view:clear;php artisan clear-compiled;composer dump-autoload;php artisan config:cache;php artisan route:cache
    
    # Use artisan serve to view
    
    php artisan serve
    
    opened by LorenzoSapora 1
  • Nested pages / routing

    Nested pages / routing

    I'm not sure if this is covered somewhere and I missed it, but is there a reliable way to have nested routing when using this package? My use case is I want to use this for a knowledgebase and for a changelog, and I'm struggling to find either a way to have multiple areas the package can search or having nested pages. Thanks!

    enhancement 
    opened by robertdrakedennis 1
Releases(v0.2.1)
  • v0.2.1(Feb 8, 2022)

    What's Changed

    • Add support for Laravel 9 by @abrardev99 in https://github.com/archtechx/laravel-pages/pull/5

    New Contributors

    • @abrardev99 made their first contribution in https://github.com/archtechx/laravel-pages/pull/5

    Full Changelog: https://github.com/archtechx/laravel-pages/compare/v0.2.0...v0.2.1

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Aug 12, 2021)

  • v0.1.0(Aug 6, 2021)

Owner
ARCHTECH
Meticulously architected web applications.
ARCHTECH
A highly configurable markdown renderer and Blade component for Laravel

A highly configurable markdown renderer and Blade component for Laravel This package contains: a Blade component that can render markdown a highly con

Spatie 230 Jan 7, 2023
Symfony 5 bundle to easily create dynamic subpages with Markdown. Useful for help sections and wikis.

MarkdownWikiBundle This bundle allows you to create rich subpages in a Symfony project using Markdown. Pages are stored in a file cache and sourced fr

Gigadrive UG 3 Apr 26, 2022
Generate pseudo-static pages from markdown and HTML files for Flarum

Flarum Pages Generator This is not a Flarum extension. This package provides a Flarum extender that you can use in the local extend.php to define cust

Clark Winkelmann 7 Feb 21, 2022
Docbook Tool for static documentation generation from Markdown files

Roave Docbook Tool Static HTML and PDF generator tool for generating documentation from Markdown files. Generates a deployable HTML file from Markdown

Roave, LLC 40 Dec 14, 2022
Gruik ! An open-source markdown note-taking web app. [ABANDONED PROJECT]

What is Gruik ? It's a free & open-source note-taking service. A space where you can store notes, tutorials, code snippets... by writing them in markd

Adrien Pétremann 329 Dec 14, 2022
A PHP tool to generate templateable markdown documentation from the docblocks or type-hints of your codebase.

Roster Installation To install, simply require the package using composer: composer require

Jordan LeDoux 14 Sep 25, 2022
Better Markdown Parser in PHP

Parsedown Better Markdown Parser in PHP - Demo. Features One File No Dependencies Super Fast Extensible GitHub flavored Tested in 5.3 to 7.3 Markdown

Emanuil Rusev 14.3k Dec 28, 2022
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.

league/commonmark league/commonmark is a highly-extensible PHP Markdown parser created by Colin O'Dell which supports the full CommonMark spec and Git

The League of Extraordinary Packages 2.4k Dec 29, 2022
Convert HTML to Markdown with PHP

HTML To Markdown for PHP Library which converts HTML to Markdown for your sanity and convenience. Requires: PHP 7.2+ Lead Developer: @colinodell Origi

The League of Extraordinary Packages 1.5k Jan 3, 2023
Render colored Markdown contents on console terminal

cli-markdown Render colored markdown contents on console terminal Preview run demo by php example/demo.php Features support auto render color on termi

PHPComLab 6 Sep 29, 2022