[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Business.php
<?php namespace App\Models; use App\Models\BusinessSetting; use App\Models\BusinessType; use App\Models\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; class Business extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'business'; protected static function booted(): void { if (auth()->check()) { static::addGlobalScope('business_id', function (Builder $builder) { if (request()->has('activeBusiness')) { $builder->whereIn('business.id', request()->businessList->pluck('id')); } }); } } public function scopeActive($query) { return $query->where('status', 1); } public function scopeOwner($query) { return $query->where('user_id', auth()->id()); } public function business_type() { return $this->belongsTo(BusinessType::class, 'business_type_id')->withDefault(); } public function user() { return $this->belongsTo(User::class, 'user_id')->withDefault(); } public function systemSettings() { return $this->hasMany(BusinessSetting::class, 'business_id'); } public function invoices() { return $this->hasMany(Invoice::class, 'business_id')->withoutGlobalScopes(); } public function quotations() { return $this->hasMany(Quotation::class, 'business_id')->withoutGlobalScopes(); } public function users() { return $this->belongsToMany(User::class, 'business_users')->withPivot('owner_id', 'role_id')->withTimestamps(); } public function role() { return $this->belongsToMany(Role::class, 'business_users')->withTimestamps(); } public static function createDefaultBusiness() { DB::beginTransaction(); $businesstype = BusinessType::first(); if (!$businesstype) { $businesstype = new BusinessType(); $businesstype->name = 'Others'; $businesstype->status = 1; $businesstype->save(); } $business = new Business(); $business->name = 'Default Business'; $business->user_id = auth()->id(); $business->business_type_id = $businesstype->id; $business->logo = 'default/default-company-logo.png'; $business->status = 1; $business->default = 1; $business->country = get_option('country', 'United States of America'); $business->currency = get_option('currency', 'USD'); $business->save(); $business->users()->attach($business->user_id, ['owner_id' => $business->user_id, 'is_active' => 1]); DB::commit(); return $business; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.81 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:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002