PHP code example of hxm / laravel-planning

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

    

hxm / laravel-planning example snippets




use HXM\LaravelPlanning\Events;
use HXM\LaravelPlanning\Listeners;
use HXM\LaravelPlanning\Models;

return [
    "resources" => [
        // \App\User::class
    ], // string[] resource list
    "useMigration" => true,
    "tables" => [
        "prefix" => '',
        "plan" => 'plans',
        "item" => 'plan_items',
        "itemPercentPrice" => 'plan_item_percent_prices',
        "condition" => 'plan_conditions',
        "order" => 'plan_orders',
        "orderItem" => 'plan_order_items',
        "orderItemPercentPrice" => 'plan_order_item_percent_prices',
        "orderLog" => 'plan_order_logs',
        "cycle" => 'plan_cycles',
        "cycleItem" => 'plan_cycle_items',
        "cycleSchedule" => 'plan_schedules',
    ],
    "models" => [
        "plan" => Models\Plan::class,
        "item" => Models\PlanItem::class,
        "itemPercentPrice" => Models\PlanItemPercentPrice::class,
        "condition" => Models\PlanCondition::class,
        "order" => Models\PlanOrder::class,
        "orderItem" => Models\PlanOrderItem::class,
        "orderLog" => Models\PlanOrderLog::class,
        "cycle" => Models\PlanCycle::class,
        "cycleItem" => Models\PlanCycleItem::class,
    ],
    "listeners" => [
        Events\PlanOrderCreatedEvent::class => function (Events\PlanOrderCreatedEvent $event) {
            $event->planOrder->addLog('Created');
        },
        Events\PlanCycleCreatedEvent::class => [],
        Events\PlanCycleUpdatedStatusEvent::class => [
            Listeners\CreatePlanScheduleWhenCycleChangedStatus::class,
            function (Events\PlanCycleUpdatedStatusEvent $event) {
                $event->planCycle->planOrder->addLog('cycle#' . $event->planCycle->getKey() . ' change Status from ' . $event->preStatus . ' to ' . $event->planCycle->status, $event->planCycle->getReferable());
            }
        ],
    ],
    "schedule" => true,
    "cron" => '10 0 * * *',
    "pannel" => [
        "enable" => true,
        "prefix" => "plans",
        "as" => "plans.",
        "middleware" => ["web", "auth"]
    ]
];

"resources" => [
    \App\User::class
],

use HXM\LaravelPlanning\LaravelPlanning;

public function boot()
{
    LaravelPlanning::addResources([\App\User::class]);
}

use HXM\LaravelPlanning\Traits\HasPlanResourceInstance;
use HXM\LaravelPlanning\Contracts\PlanResourceInstance;

class User extends Authenticatable implements PlanResourceInstance
{
    use HasPlanResourceInstance;
}

"pannel" => [
    "enable" => true,
    "prefix" => "plans",
    "as" => "plans.",
    "middleware" => ["web", "auth"]
]

use App\User;
use HXM\LaravelPlanning\Actions\Creations\CreatePlanOrderCalculator;
use HXM\LaravelPlanning\Models\Plan;

$user = User::find(1);
$plan = Plan::find(1);
$action = new CreatePlanOrderCalculator($user, $plan);

$startAt = now();
$numberOfCycle = 1;
$planOrder = $action->handle($startAt, $numberOfCycle);

// Save the plan order instance to the database
$planOrder->save();

// Get Items
$planOrder->getItems();

// Get Cycle list
$planOrder->getCycles();

// Optionally, initialize a payment for the plan order
// This can be done before or after saving the plan order.

$planCycle = $planOrder->getCycles()->last();

$planCycle->referable()->associate($payment);
$planCycle->save();

use Illuminate\Database\Eloquent\Model;
use HXM\LaravelPlanning\Models\PlanCycle;
use HXM\LaravelPlanning\Actions\Updates\UpdatePlanCycleStatus;

UpdatePlanCycleStatus::handle(PlanCycle $planCycle,int $newStatus, Model $resource);
// Or
UpdatePlanCycleStatus::handleByReferable(Model $payment, int $newStatus);

$usersWithCurrentCycle = User::withCurrentCycle()->get();

$usersWithActiveCycle = User::hasActiveCycle()->get();
bash
php artisan vendor:publish --tag="laravel-planning:config"
bash
php artisan vendor:publish --tag="laravel-planning:migration"