PHP code example of larawave / logic-as-data

1. Go to this page and download the library: Download larawave/logic-as-data 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/ */

    

larawave / logic-as-data example snippets


return [
    App\Providers\AppServiceProvider::class,
    App\Providers\LogicAsDataServiceProvider::class, // Add this line
];

'providers' => [
    // ... other providers
    App\Providers\LogicAsDataServiceProvider::class, // Add this line
],

Gate::define('viewLogicAsData', function () {
    return app()->environment('local');
});

Gate::define('viewLogicAsData', function ($user) {
    return in_array($user->email, [
        '[email protected]',
        '[email protected]',
    ]);
});

Gate::define('viewLogicAsData', function ($user) {
    // Allows access if the user has the 'view-admin-panels' permission
    return $user->can('view-admin-panels');
});

Gate::define('viewLogicAsData', function ($user) {
    if (app()->environment('local')) {
        return true;
    }

    return $user && $user->id === 1; // Replace 1 with actual value
});

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\LogicAsData\Extractors\UserLoyaltyExtractor;
use App\LogicAsData\Actions\ApplyDiscountAction;

class LogicAsDataServiceProvider extends ServiceProvider
{
    /**
     * Map source aliases to their Source Extractor classes.
     */
    private array $extractors = [
        'user.loyalty_tier' => UserLoyaltyExtractor::class,
    ];

    /**
     * Map action aliases to their Action classes.
     */
    private array $actions = [
        'cart.apply_discount' => ApplyDiscountAction::class,
    ];
    
    // ... operators, resolvers, and evaluators arrays
}
bash
php artisan logic-as-data:install