# fluent-cart/1.6.4/app/Models/TaxClass.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.4. 91 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Models/TaxClass.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Models/TaxClass.php
- Modified: 2026-06-11T12:21:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Models/TaxClass.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Models;
use FluentCart\Framework\Support\Str;

/**
 *  Meta Model - DB Model for Meta table
 *
 *  Database Model
 *
 * @package FluentCart\App\Models
 *
 * @version 1.0.0
 */
class TaxClass extends Model
{
	protected $table = 'fct_tax_classes';

	protected $primaryKey = 'id';

	protected $guarded = [ 'id' ];

	protected $fillable = [
		'title',
        'meta',
		'slug'
	];

    protected static function booted()
    {
        static::creating(function ($model) {
            if (!$model->slug) {
                $model->slug = static::generateUniqueSlug($model->title);
            }
        });

        static::updating(function ($model) {
            $protectedSlugs = ['standard', 'reduced', 'zero'];
            if ($model->isDirty('title') && !in_array($model->getOriginal('slug'), $protectedSlugs, true)) {
                $model->slug = static::generateUniqueSlug($model->title, $model->id);
            }
        });
    }

    protected static function generateUniqueSlug($title, $ignoreId = null)
    {
        $base = Str::slug($title);
        if (!$base) {
            $base = 'tax-class';
        }

        $slug = $base;
        $suffix = 2;

        while (static::query()
            ->when($ignoreId, function ($q) use ($ignoreId) {
                $q->where('id', '!=', $ignoreId);
            })
            ->where('slug', $slug)
            ->exists()) {
            $slug = $base . '-' . $suffix;
            $suffix++;
        }

        return $slug;
    }
	
	public function setMetaAttribute($value)
    {
        if ($value) {
            $decoded = \json_encode($value, true);
            if (!($decoded)) {
                $decoded = '[]';
            }
        } else {
            $decoded = '[]';
        }

        $this->attributes['meta'] = $decoded;
    }

    public function getMetaAttribute($value)
    {
        if (!$value) {
            return [];
        }

        return \json_decode($value, true);
    }
}

```
