Static Pages

Every application need some static pages such as Privacy, Terms, About, etc.

Laraloop has a basic managment of static pages which can be optionally used. You can also mix static pages from database and static page directly in view as HTML. This allow for example to have complex static page such as About stored as view blade in filesystem, or simple static pages like Privacy stored in database. And you can also mix some content in database and some content in view, by allowing your customer to edit via admin part of content.

Below is explained how to manage it.


First of all it's important to understand how routes works.

The most easy way to create routes would be,, etc.

But often your customers want to have URLs such as,, etc.

Per default Laraloop has below routes defined:

 Route::get('{pageSlug}', 'PageController@show')->name('')
    // This allow to restrict the route only to below defined slug.
    ->where('pageSlug', 'about|privacy');

This allow to restrict PageController to URL and, which is the default static pages in Laraloop. Then you can generate URL using:

 <a href="{{ route('', 'about') }}">About</a>
 <a href="{{ route('', 'privacy') }}">Privacy</a>

The PageController::show() method looks like below with added comment for better understanding.

    public function show($pageSlug)
        // Retrieve page by slug
        $page = $this->page->whereSlug($pageSlug)->first();

        // Check if exist custom view in package laraloop/frontend/views/pages/{$pageSlug}.blade.php  
        // or in app root views/pages/{$pageSlug}.blade.php
        if(view()->exists("frontend::pages.{$pageSlug}") || view()->exists("pages.{$pageSlug}")) {
            // At this point we load the custom view passing $page
            // Even if $page doesn't exist in database, this will works.
            // If exist, you can mix static content in view, with content from database.
            return view("frontend::pages.{$pageSlug}", compact('page'));

        // If there is not custom view, nor content in database, then raise page not found
        abort_unless($page, 404);

        // Load default view with content in database
        return view('', compact('page'));

If you don't have many static pages and want to manage all as static views, then you can add below routes in your web.php and so load immediately the views.

Route::view('about', 'pages.about');
Route::view('privacy', 'pages.privacy');

It's important to take into account that if you define routes without ->where() like below, then you must load this route as last.

 // Must be defined as last route
 Route::get('{pageSlug}', 'PageController@show')->name('');
  // Can be defined where you want
 Route::get('page/{pageSlug}', 'PageController@show')->name('');
 // or
 Route::get('{pageSlug}', 'PageController@show')->name('')->where('pageSlug', 'about|privacy');

Another alternative could be to use a callback function, and define custom URL which load specific page, example:

  Route::get('my-custom-url', function () {
    $controller = app(\Laraloop\Frontend\Http\Controllers\PageController::class);
    return $controller->show('my-custom-page-slug');

Manage static pages

You can create, edit and delete static pages from admin area, and then optionally create custom view to load content. If all of your content is only inside view then you don't need to create the static page in database. And if all content is inside database, then you don't need to create view.

That is all, let me know if I missed something or if something is not clear.