ok

Mini Shell

Direktori : /proc/self/root/home2/selectio/www/billingsoftwarenew/core/app/Traits/
Upload File :
Current File : //proc/self/root/home2/selectio/www/billingsoftwarenew/core/app/Traits/GlobalStatus.php

<?php

namespace App\Traits;

use App\Constants\Status;
use Illuminate\Database\Eloquent\Casts\Attribute;

trait GlobalStatus {

    public static function changeStatus($id) {
        $modelName = get_class();
        $query     = $modelName::findOrFail($id);

        if ($query->status == Status::ENABLE) {
            $query->status = Status::DISABLE;
            $message = 'Disabled successfully';
        } else {
            $query->status = Status::ENABLE;
            $message = 'Enabled successfully';
        }

        $query->save();
        $notify[] = ['success', $message];
        return back()->withNotify($notify);
    }

    public function statusBadge(): Attribute {
        return new Attribute(
            get: fn () => $this->badgeData(),
        );
    }

    public function badgeData() {
        $html = '';
        if ($this->status == Status::ENABLE) {
            $html = '<span class="badge badge--success">' . trans('Enabled') . '</span>';
        } else {
            $html = '<span class="badge badge--danger">' . trans('Disabled') . '</span>';
        }
        return $html;
    }

    public function scopeActive($query) {
        return $query->where('status', Status::ENABLE);
    }

    public function scopeInactive($query) {
        return $query->where('status', Status::DISABLE);
    }
}

Zerion Mini Shell 1.0