PHP code example of inova / nova-admin

1. Go to this page and download the library: Download inova/nova-admin 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/ */

    

inova / nova-admin example snippets


// bootstrap/app.php
->withRouting(
    web: __DIR__.'/../routes/web.php',
    then: fn () => Route::middleware('nova.public')->group(base_path('routes/public.php')),
)

purge_edge_cache('domain_switched');            // 当前请求 / 命令 / 队列任务结束时清
purge_edge_cache('domain_switched', now: true); // 立即清,返回是否成功

site_setting('copyright');        // 站点设置值,未保存过时回退 nova-admin.site_defaults
site_media_url('logo_path');      // 上传的 Logo / Favicon 的 URL,未设置返回 null

site_config('site_name');        // 读站点配置

// Facade
use Inova\NovaAdmin\Facades\SiteConfig;
SiteConfig::get('site_name', 'default');
SiteConfig::set('site_name', 'My Site');         // string
SiteConfig::set('ads_enabled', true, 'boolean'); // 按 type 存取

// config/nova-admin.php
'static_pages' => [
    'frontend' => [
        'view'       => 'pages.show',   // 换成你的 Blade,收 $page 变量
        'route_name' => 'pages.show',
    ],
],

// routes/web.php(NOVA_STATIC_FRONTEND=false 关闭包路由)
Route::get('/{slug}', function (string $slug) {
    abort_unless($page = static_page($slug), 404);

    return view(theme_view('page'), compact('page'));
})->whereIn('slug', array_keys(config('nova-admin.static_pages.presets')))->name('pages.show');

use Inova\NovaAdmin\Facades\Sitemap;

Sitemap::register(fn () => Article::published()->get()->map(fn ($a) => [
    'loc'      => route('articles.show', $a),
    'lastmod'  => $a->updated_at,          // 可选,DateTime 或字符串
    'priority' => '0.7',                   // 可选;changefreq 同理
]));

   'site_presets' => [
       'vertical' => ['label' => '垂直领域', 'provider' => VerticalPresetProvider::class, 'initial' => env('NOVA_PRESET_VERTICAL')],
   ],
   

'panel'        => ['id' => 'admin'],
'ad_positions' => [ /* 自定义广告位枚举 */ ],
'ads_protocol' => ['version' => 1, 'position_map' => [ /* 协议键 => position */ ]],
'ad_layout_positions' => ['anchor' => true, 'interstitial' => true],  // 布局级位
'ad_disabled_views'   => ['pages.show', 'errors::404'],             // 不投广告的视图
'page_cache'   => ['ttl' => 3600, 'cdn_ttl' => 86400],
'cloudflare'   => ['api_token' => env('CLOUDFLARE_API_TOKEN'), 'zone_id' => env('CLOUDFLARE_ZONE_ID')],
'security'     => ['hsts' => true],
'navigation'   => [
    'groups' => ['settings' => '基础设置', 'content' => '内容管理', 'system' => '系统'],
    'sort' => 90,
],
'admin'        => ['default_name' => 'nova', 'login_field' => 'name'],
'admin_brand'  => ['logo_link_to_front' => true, 'front_url' => '/', 'new_tab' => true],
'ads_txt'      => ['enabled' => true, 'empty_behavior' => 'delete'],
'site_settings' => [   // 站点设置页的上传限制,max_size 单位 KB,0 = 不限
    'favicon' => ['accepted_types' => ['image/x-icon', 'image/png'], 'max_size' => 1024],
    'logo'    => ['max_size' => 2048],
],
'robots_txt'   => ['enabled' => true, 'sitemap_url' => null],
'static_pages' => [
    'enabled' => true,
    'presets' => [ /* slug => [英文, 中文],安装时预置;置 enabled=false 关闭整个功能 */ ],
],
bash
php artisan nova-admin:install
bash
php artisan serve
blade
{{-- layouts/app.blade.php --}}
<head>
    @stack('ad-head')   {{-- 页面内容位的 head,必须在下面组件之前 --}}
    <x-ad-layout-head :enabled="($section ?? null)?->ads_enabled ?? true" />  {{-- global_head 固定最后 --}}
</head>
<body>
    @yield('content')
    <x-ad-layout-body :enabled="($section ?? null)?->ads_enabled ?? true" />  {{-- 不套居中容器 --}}
</body>

{{-- 页面模板里的内容位:head 与 body 必须成对,无生效广告时不产生 DOM --}}
@push('ad-head')
    <x-ad-head position="home_banner1" />
@endpush
<x-ad-body position="home_banner1" />
blade
@php($page = static_page('privacy-policy'))

@if ($page)
    <h1>{{ $page->title }}</h1>
    <div class="prose">{!! $page->body_html !!}</div>
@endif
bash
php artisan nova-admin:install --force
php artisan optimize:clear && php artisan optimize