PHP code example of ewk / moonshine-resource-kit

1. Go to this page and download the library: Download ewk/moonshine-resource-kit 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/ */

    

ewk / moonshine-resource-kit example snippets


use Ewk\MoonShineResourceKit\Concerns\Sortable;

class Article extends Model
{
    use Sortable;
}

Article::query()->orderedBySort()->get();   // ... ->orderedBySortDesc()

$article->moveUp();
$article->moveDown();
$article->moveToStart();
$article->moveToEnd();
$article->moveToPosition(7);

public function getSortColumn(): string
{
    return 'position';
}

public function getSortGroupColumns(): array
{
    return ['page_id'];
}

use Ewk\MoonShineResourceKit\MoonShine\Concerns\WithReorderable;

class ArticleResource extends ModelResource
{
    use WithReorderable;
}

use Ewk\MoonShineResourceKit\MoonShine\Concerns\ReorderableIndex;

class ArticleIndexPage extends IndexPage
{
    use ReorderableIndex;
}

protected function modifyListComponent(ComponentContract $component): ComponentContract
{
    return $this->getResource()->applyReorderable($component, $this);
}

use Ewk\MoonShineResourceKit\MoonShine\Buttons\ReorderButtons;

protected function buttons(): ListOf
{
    return parent::buttons()->prepend(...ReorderButtons::for($this->getResource()));
}

use Ewk\MoonShineResourceKit\MoonShine\Fields\SortHandle;

protected function fields(): iterable
{
    return [
        SortHandle::make(),
        ID::make(),
        // ...
    ];
}

protected function reorderableWithHandle(): bool  // на индексной странице с ReorderableIndex
{
    return true;
}

HasMany::make('Blocks', resource: BlockResource::class)
    ->modifyTable(app(BlockResource::class)->reorderableTableModifier()),

use Ewk\MoonShineResourceKit\Concerns\Activatable;

class Article extends Model
{
    use Activatable;
}

use Ewk\MoonShineResourceKit\MoonShine\Concerns\WithActivatable;

class ArticleResource extends ModelResource
{
    use WithActivatable;
}

use Ewk\MoonShineResourceKit\MoonShine\Fields\ActiveSwitcher;

protected function fields(): iterable
{
    return [
        // ...
        ActiveSwitcher::make('Активность'),
    ];
}

use Ewk\MoonShineResourceKit\MoonShine\Buttons\ActivityButtons;

protected function buttons(): ListOf
{
    return parent::buttons()->prepend(...ActivityButtons::for($this->getResource()));
}

use Ewk\MoonShineResourceKit\Scopes\ActiveScope;

protected static function booted(): void
{
    static::addGlobalScope(new ActiveScope());
}

// обходной путь:
Article::query()->withInactive()->get();

use Ewk\MoonShineResourceKit\Concerns\HasActiveFactoryStates;

class ArticleFactory extends Factory
{
    use HasActiveFactoryStates;
}

ArticleFactory::new()->active()->create();
ArticleFactory::new()->inactive()->create();
ArticleFactory::new()->randomActive()->create();
bash
php artisan vendor:publish --tag=moonshine-resource-kit-config
php artisan vendor:publish --tag=moonshine-resource-kit-lang