Installs: 1 495

Dependents: 1

Suggesters: 0

Security: 0

Type:package

0.5.0 2024-03-15 17:14 UTC

This package is auto-updated.

Last update: 2024-03-18 08:27:13 UTC


README

This package is used as a base for SCTeam

Installation

1. Require package in your composer.json:

  • composer require studiocreativateam/base

Run below command to overwrite config/breadcrumbs.php settings

php artisan vendor:publish --provider="SCTeam\Base\SCTeamServiceProvider" --tag="config-base" --force

Publishing

In this package you can publish below files:

  • views php artisan vendor:publish --provider="SCTeam\Base\SCTeamServiceProvider" --tag="views"
  • config php artisan vendor:publish --provider="SCTeam\Base\SCTeamServiceProvider" --tag="config"

Clear cache / delete cached js-css files

Command: php artisan cache:flush Get request: /admin/cache/flush

add to composer.json:

{
  "scripts": {
    "post-autoload-dump": [
      "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
      ...
      "@php artisan cache:flush"
    ]
  }
}

Clear cache by keys:

ClearCacheFiredEvent::dispatch([...keys])

How to add global scope:

  1. Create Scope class:
    <?php
    

namespace SCTeam\Package\Scopes;

use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use SCTeam\Package\Models\Some; use SCTeam\Base\Models\GlobalScope;

class InCompany extends GlobalScope {

public static function model(): array|string
{
    return [
        \SCTeamAuth::userModelClass(),
        Some::class,
    ];
}

public function apply(Builder $builder, Model $model): void
{
    $builder->whereHas('company');
}

}

in the _model_ function, pass the names of the models for which globalscope is to be applied
2. Declare your custom global scope in service provider:

class SCTeamServiceProvider extends BaseSCTeamServiceProvider {

/// ...
protected function globalScopes(): array|string
{
    return InCompany::class;
}
/// ...

}

3. Add trait to your model:

use HasHookGlobalScope;


# Sidebar configuration
### Add to config/config.php

'sidebar_elements' => [

\SCTeam\Base\Enums\LeftSidebarHook::Shop => [
    100 => [ /// 100 is priority
        'key' => 'some-key', // use to dynamic submenu positions
        'text' => 'scteam.package::common.some',
        'icon' => 'fa-solid fa-info',
        'badge' => [SomeRepository::class, 'method'],
        'submenu' => [
            100 => [
                'text' => 'scteam.package::common.somes',
                'route' => 'package.somes.index',
                'active' => ['admin/package/somes*'],
                'icon' => false,
                'can' => [SomePermissions::SomeList],
            ],
        ],
    ],
]

],

### How to add dynamic submenu position

'sidebar_elements' => [

\SCTeam\Base\Enums\LeftSidebarHook::Shop => [
    360 => [
        'add_to' => 'some-key', // this is important
        'text' => 'scteam.package::common.some-sub-position',
        'route' => 'package.some-sub.index',
        'icon' => false,
        'active' => ['admin/package/some-sub*'],
        'can' => [SomeSubPermissions::SomeSubList]
    ]
]

],