Comment on page
PageData
Your page data class should extend
\Astrotomic\Stancy\Models\PageData
and define all possible attributes via public properties including a doc-tag with all possible types (FQCN for objects).app/Pages/Blog.php
<?php
namespace App\Pages;
class Blog extends PageData
{
/** @var string */
public $title;
/** @var \Carbon\Carbon */
public $date;
/** @var \App\Pages\Post[] */
public $posts;
}
The package comes with some ready to use traits with the most common attributes.
\Astrotomic\Stancy\Traits\PageHasContent
adds thecontents
attribute (used by markdown content parsers)\Astrotomic\Stancy\Traits\PageHasDate
adds thedate
attribute (used by\Spatie\Sheets\PathParsers\SlugWithDateParser
)\Astrotomic\Stancy\Traits\PageHasOrder
adds theorder
attribute (used by\Spatie\Sheets\PathParsers\SlugWithOrderParser
)\Astrotomic\Stancy\Traits\PageHasSlug
adds theslug
attribute (used by path parsers)
app/Pages/Blog.php
<?php
namespace App\Pages;
use Astrotomic\Stancy\Models\PageData;
use Astrotomic\Stancy\Traits\PageHasContent;
use Astrotomic\Stancy\Traits\PageHasSlug;
class Blog extends PageData
{
use PageHasSlug, PageHasContent;
}
The package comes with a
\Astrotomic\Stancy\Contracts\Routable
interface which defines a getUrl()
method. You can combine it with the \Astrotomic\Stancy\Traits\PageHasUrl
trait which defines the toSitemapItem()
method by using the getUrl()
return value. It's also great to get the page url in a view or for the feed item transformation.app/Pages/Blog.php
<?php
namespace App\Pages;
use Astrotomic\Stancy\Contracts\Routable;
use Astrotomic\Stancy\Models\PageData;
use Astrotomic\Stancy\Traits\PageHasUrl;
class Blog extends PageData implements Routable
{
use PageHasUrl;
public function getUrl(): string
{
return url('/blog');
}
}
Last modified 4yr ago