PHP code example of antweb / fusion-antfusion

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

    

antweb / fusion-antfusion example snippets



namespace App\AntFusion;

abstract class Resource extends \Addons\AntFusion\Resource {
}

    
    namespace App\AntFusion;
    
    use App\Models\User;
    use Addons\AntFusion\Fields\Fusion as FusionField;
    
    class NewResource extends Resource
    {
        protected $model = User::class; // Model class of the resurce
        protected $clickColumnHandle = 'name';
    
        public function fields() {
            return [
                FusionField::make('Name', 'name')->asName(),
            ];
        }
    
        public function actions() {
            return [
                // \Addons\AntFusion\Actions\Create::make()->primary(),
                new \Addons\AntFusion\Actions\Edit,
            ];
        }
    }
    

    (new \App\AntFusion\NewResource)->register();
    

    class NewResource extends Resource
    {
    	protected $slug = 'user-list';
    }
    

    class NewResource extends Resource
    {
    	protected $icon = 'users';
    }
    

    class NewResource extends Resource
    {
    	protected $name= 'Users';
    }
    

    
    namespace App\AntFusion\Pages;
    
    class NewPage extends \Addons\AntFusion\Page
    {
    		public function components() {
            return [
    						
    				];
        }
    }
    

    
    namespace App\AntFusion\Actions;
    
    use Addons\AntFusion\Action;
    
    class NewAction extends Action
    {
    	// protected $name = 'Custom Label Name';
    
    	// protected $standalone = true; // For non-inline action
    
    	public function handle($request, $entries) {
    		// $entry = $entries->first(); // For inline action
    	}
    }
    

    public function actions() {
    	return [
    		new \App\AntFusion\Actions\NewAction
    	];
    }
    
    // OR (with confirmation message)
    public function actions() {
    	return [
    		(new \App\AntFusion\Actions\NewAction)->confirmText('Are you sure?'),
    	];
    }
    

class NewAction extends Action
{
		public function __construct() {
        $this->withMeta(['load_record' => [
            'name' => 'name',
            'contact_number' => 'profile.contact_number',
        ]]);
    }

		public function fields() {
        return [
            Fusion::make('Name', 'name')->type('input'),
            Fusion::make('Contact Number', 'contact_number')->type('input'),
        ];
    }
}

use Addons\AntFusion\Actions\Link;

Link::make('View', '/resource/user-list/view')->onlyInline();

use Addons\AntFusion\Actions\Link;

Link::make('View', function($model) {
    return '/resource/user-list/'.$model->id.'/user-detail';
})->onlyInline(),


namespace App\AntFusion\Filters;

use Addons\AntFusion\Filter;

class BookFilter extends Filter
{
    const LISTED = 'listed';
    const DELISTED = 'delisted';

    public function apply($request, $query, $value) {
        if ($value == static::LISTED) {
            $query->listed();
        } else if ($value == static::DELISTED) {
            $query->delisted();
        } else {
            $query->listed();
        }
    }

    public function options($request)
    {
        return [
            'Listed' => static::LISTED,
            'Delisted' => static::DELISTED,
        ];
    }
}

public function filters()
{
    return [
        new \App\AntFusion\Filters\BookFilter,
    ];
}


namespace App\AntFusion\Metrics;

use Addons\AntFusion\Components\MetricCard;

class Balance extends MetricCard
{
    public function __construct() {
        $this->label('Balance')->icon('minus');
    }

    public function calculate()
    {
        return $this->query()->sum('debit') - $this->query()->sum('credit');
    }
}

public function metrics()
{
    return [
        new \App\AntFusion\Metrics\Balance,
    ];
}

use Addons\AntFusion\Components\Panel;

public function fields() {
    return [
        Panel::make('', [
					// Fields inside panel
				]),
		]
}

[
	Panel::make('', [
		// Fields inside panel
	])->width('2/3'),

	Panel::make('', [
		// Fields inside panel
	])->width('1/3'),
]