-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
61 lines (54 loc) · 1.83 KB
/
helper.php
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
<?php
use Illuminate\Support\Facades\DB;
if (!function_exists('hasModelPermission')) {
function hasModelPermission($key, $model)
{
return true;
$post = DB::table('customers')
->leftJoin('subscriptions', 'customers.id', '=', 'subscriptions.customer_id')
->leftJoin('features', 'subscriptions.feature_id', '=', 'features.id')
->where('customers.admin_id', auth()->id())
->where('key', $key)
->select('features.key', 'subscriptions.number_of_records', 'customers.id as customer_id')
->get()
->first();
if (!$post) {
return false;
}
$productsCount = $model::where('customer_id', $post->customer_id)
->count();
if ($productsCount < $post->number_of_records) {
return true;
} else {
return false;
}
}
}
//get the number of records based on the model key
if (!function_exists('getNumberOfModelRecords')) {
function getNumberOfModelRecords($Modelkey)
{
$post = DB::table('customers')
->leftJoin('subscriptions', 'customers.id', '=', 'subscriptions.customer_id')
->leftJoin('features', 'subscriptions.feature_id', '=', 'features.id')
->where('customers.admin_id', auth()->id())
->where('key', $Modelkey)
->select('features.key', 'subscriptions.number_of_records', 'customers.id as customer_id')
->get()
->first();
if (!$post) {
return 0;
}
return $post->number_of_records;
}
}
// format the number of records 1000 to 1k
if (!function_exists('formatNumber')) {
function formatNumber($number)
{
if ($number >= 1000) {
return number_format($number / 1000, 1) . 'k';
}
return $number;
}
}