PHP code example of sierratecnologia / siravel

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

    

sierratecnologia / siravel example snippets


return [
    // Negócio/organização padrão
    'default' => env('SIRAVEL_DEFAULT_BUSINESS', 'ricasolucoes'),

    // Prefixo de tabelas do banco de dados
    'db-prefix' => env('SIRAVEL_DB_PREFIX', ''),

    // Paginação padrão
    'pagination' => env('SIRAVEL_PAGINATION', 25),

    // Tema frontend padrão
    'frontend-theme' => env('SIRAVEL_THEME', 'default'),

    // Habilitar multi-tenancy
    'multi-tenant' => env('SIRAVEL_MULTI_TENANT', true),

    // Configurações de features
    'features' => [
        'blog' => true,
        'commerce' => true,
        'travels' => false,
        // ... outras features
    ],
];

use Siravel\Services\BusinessService;

// Obter o negócio atual baseado no domínio
$business = app(BusinessService::class)->getCurrentBusiness();

// Alternar contexto de tenant
Business::set($business);

// Verificar features ativas para o tenant
if (Features::isActive('commerce')) {
    // Lógica de e-commerce
}

use Siravel\Facades\Features;

// Verificar se uma feature está ativa
if (Features::isActive('blog')) {
    // Código do blog
}

// Ativar feature para um negócio
$business->features()->attach('commerce');

// Desativar feature
$business->features()->detach('travels');

use Siravel\Models\Negocios\Business;

$business = Business::create([
    'name' => 'Minha Empresa',
    'slug' => 'minha-empresa',
    'domain' => 'empresa.com.br',
    'settings' => [
        'theme' => 'corporate',
        'timezone' => 'America/Sao_Paulo',
    ],
]);

// Ativar features
$business->features()->attach(['blog', 'commerce']);

use Siravel\Models\Blog\Post;
use Siravel\Models\Blog\Category;

// Criar categoria
$category = Category::create([
    'name' => 'Tecnologia',
    'slug' => 'tecnologia',
]);

// Criar post
$post = Post::create([
    'title' => 'Título do Post',
    'slug' => 'titulo-do-post',
    'content' => 'Conteúdo do post...',
    'category_id' => $category->id,
    'published_at' => now(),
    'is_published' => true,
]);

// Buscar posts publicados
$posts = Post::published()->latest()->paginate(15);

use Siravel\Models\Commerce\Product;
use Siravel\Models\Commerce\Order;
use Siravel\Models\Commerce\Cart;

// Criar produto
$product = Product::create([
    'name' => 'Produto Exemplo',
    'slug' => 'produto-exemplo',
    'description' => 'Descrição do produto',
    'price' => 99.90,
    'stock' => 100,
]);

// Adicionar ao carrinho
$cart = Cart::addItem($product, $quantity = 2);

// Criar pedido
$order = Order::createFromCart($cart, $user);

use Siravel\Models\Negocios\Page;
use Siravel\Models\Negocios\Menu;

// Criar página
$page = Page::create([
    'title' => 'Sobre Nós',
    'slug' => 'sobre',
    'content' => 'Conteúdo da página...',
    'template' => 'default',
    'is_published' => true,
]);

// Criar menu
$menu = Menu::create([
    'name' => 'Menu Principal',
    'slug' => 'main-menu',
    'items' => [
        ['label' => 'Home', 'url' => '/'],
        ['label' => 'Sobre', 'url' => '/sobre'],
        ['label' => 'Blog', 'url' => '/blog'],
    ],
]);

// URL do storage
url_storage('images/logo.png');

// URL do frontend
url_frontend('/blog/post-slug');

// URL de login
url_frontend_sign_in();

// Asset versionado
versioned_asset('css/app.css');

// Usuário atual
$user = user();

// Verificar se está autenticado
if (signedInUser()) {
    // ...
}

// Verificar permissão
if (userCan('edit', $post)) {
    // ...
}

// Renderizar menu
menu('main-menu', 'components.menu');

// Renderizar widget
widget('sidebar-ads');

// Converter markdown para HTML
$html = markup($markdown);

// Ícone SVG
icon('user', ['class' => 'w-6 h-6']);

// Conversões seguras de tipo
$bool = to_bool($value);
$int = to_int($value);
$float = to_float($value);
$string = to_string($value);
$array = to_array($value);
$object = to_object($data, ClassName::class);

namespace Tests\Feature;

use Tests\TestCase;
use Siravel\Models\Blog\Post;

class BlogTest extends TestCase
{
    public function test_can_create_post()
    {
        $post = Post::create([
            'title' => 'Test Post',
            'content' => 'Test Content',
        ]);

        $this->assertDatabaseHas('posts', [
            'title' => 'Test Post',
        ]);
    }
}

namespace App\Services;

use Siravel\Services\BaseService;

class CustomService extends BaseService
{
    public function processData($data)
    {
        // Lógica de negócio
    }
}

namespace App\Repositories;

use Siravel\Repositories\SiravelRepository;

class CustomRepository extends SiravelRepository
{
    protected $model = CustomModel::class;

    public function findByCustomCriteria($criteria)
    {
        return $this->model->where('field', $criteria)->get();
    }
}

// Event
namespace Siravel\Events;

class BusinessNewRegister
{
    public $business;

    public function __construct($business)
    {
        $this->business = $business;
    }
}

// Listener
Event::listen(BusinessNewRegister::class, function($event) {
    // Processar novo negócio
});
bash
# Publicar tudo
php artisan vendor:publish --provider="Siravel\SiravelProvider"

# Ou publicar seletivamente
php artisan vendor:publish --tag=siravel-config
php artisan vendor:publish --tag=siravel-migrations
php artisan vendor:publish --tag=siravel-assets
bash
php artisan migrate
bash
php artisan sitec:siravel:install

tests/
├── Feature/              # Testes de integração
│   ├── BlogTest.php
│   ├── CommerceTest.php
│   └── AuthTest.php
├── Unit/                 # Testes unitários
│   ├── Models/
│   └── Services/
└── Services/             # Testes de serviços
    ├── BusinessServiceTest.php
    └── FeatureServiceTest.php
bash
# Instalar Siravel
php artisan sitec:siravel:install

# Backup do banco de dados
php artisan siravel:database:backup

# Criar negócio
php artisan siravel:business:create {name}

# Ativar feature
php artisan siravel:feature:enable {feature} {business?}

# Desativar feature
php artisan siravel:feature:disable {feature} {business?}