PHP code example of dewsign / nova-spaces

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

    

dewsign / nova-spaces example snippets


// app/Nova/SidebarSpace.php

namespace App\Nova;

use Dewsign\NovaSpaces\Nova\Space;

class SidebarSpace extends Space
{
    public static $zone = 'sidebar';

    public static function label()
    {
        return __('Sidebar Items');
    }
}

@foreach(Space::active()->whereZone('sidebar')->get() as $spaceItem)
    {!! $spaceItem->view !!}
    {!! or !!}
    <a href="{{ $spaceItem->action }}">{{ $spaceItem->label }}</a>
@endforeach

@foreach($spaceItem->spaces as $item)
    {!! $item->view !!}
@endforeach

// app/Space/Models/Section.php

use Dewsign\NovaSpaces\Models\SpaceItem;

class Section extends SpaceItem
{
    public static $repeaterBlockViewTemplate = 'space.section';

    public function resolveAction()
    {
        return $this->link_url;
    }

    public function resolveLabel($model = null)
    {
        return $model->title ?? $this->heading;
    }
}

// database/migrations/your_migration.php

Schema::create('space_sections', function (Blueprint $table) {
    $table->increments('id');
    $table->string('heading')->nullable();
    $table->text('content')->nullable();
    $table->string('link_url')->nullable();
    $table->string('link_title')->nullable();
    $table->timestamps();
});

// app/Space/Nova/Section.php

...
use Dewsign\NovaSpaces\Nova\Items\SpaceItem;

class Section extends SpaceItem
{
    public static $model = App\Space\Models\Section::class;

    public static $title = 'heading';

    public static $search = [
        'heading',
        'content',
        'link_url',
    ];

    public static function label()
    {
        return __('Section');
    }

    public function fields(Request $request)
    {
        return [
            Text::make('Heading'),
            Markdown::make('Content'),
            Text::make('Link Url'),
            Text::make('Link Title'),
        ];
    }
}

return [
    "repeaters" => [
        ...
        \App\Space\Nova\Section::class,
    ],
];