PHP code example of fullsmack / laravel-slice

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

    

fullsmack / laravel-slice example snippets


'providers' => [
    // ... other providers
    \Slice\Pizza\PizzaServiceProvider::class,
    \Slice\Order\OrderServiceProvider::class,
],

use FullSmack\LaravelSlice\Slice;
use FullSmack\LaravelSlice\SliceServiceProvider;

final class PizzaServiceProvider extends SliceServiceProvider
{
    public function configure(Slice $slice): void
    {
        $slice->setName('pizza');
    }
}

public function configure(Slice $slice): void
{
    $slice->setName('order')
        ->useRoutes()          // Load routes from routes/
        ->useViews()           // Load views from resources/views
        ->useTranslations()    // Load translations from lang/
        ->useMigrations()      // Load migrations from database/migrations
        ->withCommands([       // Register command classes
            \Slice\Order\Console\SyncOrders::class,
        ])
}

use FullSmack\LaravelSlice\Slice;
use FullSmack\LaravelSlice\Extension;

final class CustomExtension implements Extension
{
    public function register(Slice $slice): void
    {
        // Add custom functionality here
        // Access to slice configuration, paths, etc.

        // Example: Register Livewire or other frontend assets in your slice
    }
}

use FullSmack\LaravelSlice\Slice;
use FullSmack\LaravelSlice\SliceServiceProvider;

final class OrderServiceProvider extends SliceServiceProvider
{
    public function configure(Slice $slice): void
    {
        $slice->setName('order')
            ->withExtension(new CustomExtension())
            ->withExtension(new AnotherExtension());
    }
}

config('pizza::settings.default-timezone');
trans('pizza::messages.order-created');
view('pizza::emails.receipt');

    $slice->setName('cookbook')
        ->useMigrations()
        ->withConnection('cookbook');

    $slice->setName('cookbook')
        ->useMigrations()
        ->withConnection('cookbook', [
            \Slice\Cookbook\Models\Recipe::class,
            \Slice\Cookbook\Models\Ingredient::class
        ]);

use FullSmack\LaravelSlice\Testing\RefreshSliceDatabase;

final class RecipeTest extends TestCase
{
    use RefreshSliceDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->refreshSlice('pizza');
    }
}
bash
php artisan vendor:publish --provider="FullSmack\LaravelSlice\LaravelSliceServiceProvider" --tag="config"
bash
php artisan make:slice pizza
bash
php artisan make:slice pizza
php artisan make:migration create_recipes_table --create=recipes --slice=pizza
php artisan migrate --slice=pizza