File size: 1,533 Bytes
5f32fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PaymentPlans extends Model
{
    protected $table = 'plans';

    protected $fillable = [
        'active',
        'name',
        'price',
        'currency',
        'frequency',
        'is_featured',
        'is_free',
        'stripe_product_id',
        'total_words',
        'total_images',
        'ai_name',
        'max_tokens',
        'can_create_ai_images',
        'plan_type',
        'features',
        'type',
        'is_team_plan',
        'plan_allow_seat',
        'trial_days',
        'display_imag_count',
        'display_word_count',
        'open_ai_items',
        'description',
        'plan_ai_tools',
        'plan_features',
        'default_ai_model',
    ];

    protected $casts = [
        'open_ai_items' => 'json',
        'plan_ai_tools' => 'json',
        'plan_features' => 'json',
    ];

    // gateway_products
    public function gateway_products()
    {
        return $this->hasMany(GatewayProducts::class, 'plan_id', 'id');
    }

    // revenuecat_products
    public function revenuecat_products()
    {
        return $this->hasMany(RevenueCatProducts::class, 'plan_id', 'id');
    }

    public function checkOpenAiItemCount(): int
    {
        $items = is_array($this->open_ai_items) ? $this->open_ai_items : [];

        return count($items);
    }

    public function checkOpenAiItem($key): bool
    {
        $items = $this->open_ai_items ?: [];

        return in_array($key, $items);
    }
}