One Hat Cyber Team
Your IP :
3.141.43.16
Server IP :
192.145.235.60
Server :
Linux ngx365.inmotionhosting.com 5.14.0-427.33.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 30 09:45:56 EDT 2024 x86_64
Server Software :
Apache
PHP Version :
8.2.27
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
centos12
/
public_html
/
centosuit
/
app
/
Models
/
View File Name :
Lead.php
<?php namespace App\Models; use App\Enums\Salutation; use App\Scopes\ActiveScope; use App\Traits\CustomFieldsTrait; use App\Traits\HasCompany; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Notifications\Notifiable; /** * App\Models\Lead * * @property int $id * @property int|null $client_id * @property int|null $source_id * @property int|null $status_id * @property int $column_priority * @property int|null $agent_id * @property string|null $company_name * @property string|null $website * @property string|null $address * @property string|null $salutation * @property string $client_name * @property string $client_email * @property string|null $mobile * @property string|null $cell * @property string|null $office * @property string|null $city * @property string|null $state * @property string|null $country * @property string|null $postal_code * @property string|null $note * @property string $next_follow_up * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property float|null $value * @property float|null $total_value * @property int|null $currency_id * @property int|null $category_id * @property int|null $added_by * @property int|null $last_updated_by * @property-read \App\Models\User|null $client * @property-read \App\Models\Currency|null $currency * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DealFile[] $files * @property-read int|null $files_count * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DealFollowUp[] $follow * @property-read int|null $follow_count * @property-read \App\Models\DealFollowUp|null $followup * @property-read mixed $extras * @property-read mixed $icon * @property-read mixed $image_url * @property-read \App\Models\LeadAgent|null $leadAgent * @property-read \App\Models\LeadSource|null $leadSource * @property-read \App\Models\LeadStatus|null $leadStatus * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications * @property-read int|null $notifications_count * @method static \Database\Factories\LeadFactory factory(...$parameters) * @method static \Illuminate\Database\Eloquent\Builder|Lead newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Lead newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Lead query() * @method static \Illuminate\Database\Eloquent\Builder|Lead whereAddedBy($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereAddress($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereAgentId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCategoryId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCell($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCity($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereClientEmail($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereClientId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereClientName($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereColumnPriority($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCompanyName($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCountry($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCurrencyId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereLastUpdatedBy($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereMobile($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereNextFollowUp($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereNote($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereOffice($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead wherePostalCode($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereSalutation($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereSourceId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereState($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereStatusId($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereValue($value) * @method static \Illuminate\Database\Eloquent\Builder|Lead whereWebsite($value) * @property string|null $hash * @property-read \App\Models\LeadCategory|null $category * @method static \Illuminate\Database\Eloquent\Builder|Lead whereHash($value) * @property int|null $company_id * @property-read \App\Models\Company|null $company * @method static \Illuminate\Database\Eloquent\Builder|Lead whereCompanyId($value) * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Product> $products * @property-read int|null $products_count * @property-read int|null $follow_up_date_next * @property-read int|null $follow_up_date_past * @mixin \Eloquent */ class Lead extends BaseModel { use Notifiable, HasFactory; use CustomFieldsTrait; use HasCompany; const CUSTOM_FIELD_MODEL = 'App\Models\Lead'; protected $appends = ['image_url', 'client_name_salutation']; protected $casts = [ 'salutation' => Salutation::class, ]; public function getImageUrlAttribute() { $gravatarHash = !is_null($this->email) ? md5(strtolower(trim($this->email))) : ''; return 'https://www.gravatar.com/avatar/' . $gravatarHash . '.png?s=200&d=mp'; } public function clientNameSalutation(): Attribute { return Attribute::make( get: fn($value) => ($this->salutation ? $this->salutation->label() . ' ' : '') . $this->client_name ); } /** * Route notifications for the mail channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ // phpcs:ignore public function routeNotificationForMail($notification) { return $this->email; } public function leadSource(): BelongsTo { return $this->belongsTo(LeadSource::class, 'source_id'); } public function category(): BelongsTo { return $this->belongsTo(LeadCategory::class, 'category_id'); } public function note(): BelongsTo { return $this->belongsTo(LeadNote::class, 'lead_id'); } public function client(): BelongsTo { return $this->belongsTo(User::class, 'client_id'); } public function addedBy(): BelongsTo { return $this->belongsTo(User::class, 'added_by')->withoutGlobalScope(ActiveScope::class); } public function leadOwner(): BelongsTo { return $this->belongsTo(User::class, 'lead_owner')->withoutGlobalScope(ActiveScope::class); } public static function allLeads($contactId = null) { // Retrieve user's lead view permission $viewLeadPermission = user()->permission('view_lead'); // If the user has no permission to view leads if ($viewLeadPermission === 'none') { return collect(); } // Initialize lead query $leadsQuery = Lead::select('*')->orderBy('client_name'); if ($viewLeadPermission == 'owned') { $leadsQuery = $leadsQuery->where('lead_owner', user()->id); } if ($viewLeadPermission == 'added') { $leadsQuery = $leadsQuery->where('added_by', user()->id); } if ($viewLeadPermission == 'both') { $leadsQuery = $leadsQuery->where(function ($query) { $query->where('lead_owner', user()->id) ->orWhere('added_by', user()->id); }); } // Apply contact ID filter if provided if ($contactId) { $leadsQuery->where('id', $contactId); } // Retrieve leads return $leadsQuery->get(); } }