1. Go to this page and download the library: Download nvl/pages library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nvl / pages example snippets
use Nvl\Pages\Models\Page as BasePage;
use Nvl\Support\Ownership\ValueObjects\OwnershipDefinition;
class Page extends BasePage
{
public static function ownershipDefinition(): OwnershipDefinition
{
return OwnershipDefinition::column(Company::class, 'company_id');
}
}
use Nvl\Pages\Actions\CreatePageAction;
use Nvl\Pages\Data\Mutations\CreatePageData;
use Nvl\Pages\Data\PageActorData;
use Nvl\Pages\Enums\PageStatus;
use Nvl\Pages\Models\Page;
final readonly class CreateAboutPage
{
public function __construct(private CreatePageAction $createPage) {}
public function execute(): Page
{
return $this->createPage->execute(
new CreatePageData(
key: 'company.about',
slug: 'about',
status: PageStatus::Published,
translations: [
'en' => [
'title' => 'About',
'navigationLabel' => 'About',
'summary' => 'How the organization works.',
],
],
),
PageActorData::system(),
);
}
}
use Domain\Site\CatalogEntryPageHandler;
'resources' => [
'catalog.entry' => CatalogEntryPageHandler::class,
],
use Nvl\Pages\Actions\CheckPageKeyAvailabilityAction;
use Nvl\Pages\Actions\FindPageByKeyAction;
use Nvl\Pages\Actions\ListPageOptionsAction;
use Nvl\Pages\Actions\ListPublicChildPagesAction;
use Nvl\Pages\Data\PageActorData;
use Nvl\Pages\Data\PageRequestContextData;
use Nvl\Pages\Enums\PageKind;
use Nvl\Pages\Enums\PublicChildPageOrder;
$actor = PageActorData::fromAuthenticatable($user);
$page = app(FindPageByKeyAction::class)->execute('main', 'about', $actor);
$availability = app(CheckPageKeyAvailabilityAction::class)->execute(
'main',
'about',
$actor,
exceptId: $page->id,
);
$options = app(ListPageOptionsAction::class)->execute(
'main',
'bg',
$actor,
search: 'about',
);
$children = app(ListPublicChildPagesAction::class)->execute(
$page->id,
new PageRequestContextData('main', 'bg'),
limit: 24,
kind: PageKind::Static,
order: PublicChildPageOrder::Newest,
);
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Nvl\Pages\Actions\GetPageEditorBootstrapAction;
use Nvl\Pages\Actions\GetPagePublicationProjectionAction;
use Nvl\Pages\Actions\ListPageEditorSummariesAction;
use Nvl\Pages\Data\PageActorData;
final readonly class PageWorkspace
{
public function __construct(
private ListPageEditorSummariesAction $summaries,
private GetPageEditorBootstrapAction $editor,
private GetPagePublicationProjectionAction $publication,
) {}
public function index(string $site, string $locale, PageActorData $actor): LengthAwarePaginator
{
return $this->summaries->execute($site, $locale, $actor, perPage: 25);
}
public function edit(string $pageId, string $locale, PageActorData $actor): array
{
return $this->editor->execute($pageId, $locale, $actor)->toArray();
}
public function show(string $pageId, string $locale, PageActorData $actor): array
{
return $this->publication->execute($pageId, $locale, $actor)->toArray();
}
}
use Nvl\Pages\Contracts\CreatePageContract;
use Nvl\Pages\Data\Mutations\CreatePageData;
use Nvl\Pages\Data\PageActorData;
use Nvl\Pages\Models\Page;
final readonly class CreatePageWorkflow
{
public function __construct(private CreatePageContract $workflow) {}
public function execute(CreatePageData $data, PageActorData $actor): Page
{
return $this->workflow->execute($data, $actor);
}
}
use Nvl\Pages\Contracts\ListPagesContract;
$double = Mockery::mock(ListPagesContract::class);
$this->app->instance(ListPagesContract::class, $double);
// Configure the exact execute arguments and documented return value for your host case.
use Nvl\Pages\Models\Page;
$fixture = Page::factory()->withoutParents()->make();
sh
composer n nvl:install pages --dry-run
php artisan nvl:install pages