403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/project-slim/app/Repositories/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/project-slim/app/Repositories/CompanyRepository.php
<?php

namespace App\Repositories;

use App\Models\Company;
use App\Models\CompanySocial;
use App\Models\CompanyProductLink;
use App\Repositories\Interfaces\CompanyRepositoryInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;

class CompanyRepository implements CompanyRepositoryInterface
{
    /**
     * Find company by ID
     */
    public function findById(int $id): ?Company
    {
        return Company::with(['users', 'socialLinks', 'productLinks'])->find($id);
    }

    /**
     * Find company by domain
     */
    public function findByDomain(string $domain): ?Company
    {
        return Company::with(['users', 'socialLinks', 'productLinks'])
                     ->where('domain', $domain)
                     ->first();
    }

    /**
     * Create a new company
     */
    public function create(array $data): Company
    {
        $company = Company::create([
            'name' => $data['name'],
            'domain' => $data['domain']
        ]);

        // Add social links if provided
        if (isset($data['social_links']) && is_array($data['social_links'])) {
            foreach ($data['social_links'] as $social) {
                $company->addSocialLink(
                    $social['platform'],
                    $social['handle'] ?? null,
                    $social['url'] ?? null
                );
            }
        }

        // Add product links if provided
        if (isset($data['product_links']) && is_array($data['product_links'])) {
            foreach ($data['product_links'] as $product) {
                $company->addProductLink(
                    $product['platform'],
                    $product['url']
                );
            }
        }

        return $company->load(['users', 'socialLinks', 'productLinks']);
    }

    /**
     * Update company
     */
    public function update(int $id, array $data): ?Company
    {
        $company = $this->findById($id);
        if (!$company) {
            return null;
        }

        $company->update(array_filter([
            'name' => $data['name'] ?? $company->name,
            'domain' => $data['domain'] ?? $company->domain
        ]));

        // Update social links if provided
        if (isset($data['social_links']) && is_array($data['social_links'])) {
            foreach ($data['social_links'] as $social) {
                $company->updateSocialLink(
                    $social['platform'],
                    $social['handle'] ?? null,
                    $social['url'] ?? null
                );
            }
        }

        // Update product links if provided
        if (isset($data['product_links']) && is_array($data['product_links'])) {
            foreach ($data['product_links'] as $product) {
                $company->updateProductLink(
                    $product['platform'],
                    $product['url']
                );
            }
        }

        return $company->refresh();
    }

    /**
     * Delete company
     */
    public function delete(int $id): bool
    {
        $company = $this->findById($id);
        if (!$company) {
            return false;
        }

        return $company->delete();
    }

    /**
     * Get all companies with pagination
     */
    public function getAll(int $page = 1, int $limit = 20, array $filters = []): LengthAwarePaginator
    {
        $query = Company::with(['users'])
                        ->withCount(['users', 'activeUsers'])
                        ->orderBy('created_at', 'desc');

        // Apply filters
        if (isset($filters['search'])) {
            $query->search($filters['search']);
        }

        if (isset($filters['domain'])) {
            $query->byDomain($filters['domain']);
        }

        return $query->paginate($limit, ['*'], 'page', $page);
    }

    /**
     * Search companies
     */
    public function search(string $term, int $page = 1, int $limit = 20): LengthAwarePaginator
    {
        return Company::with(['users'])
                     ->withCount(['users', 'activeUsers'])
                     ->search($term)
                     ->orderBy('created_at', 'desc')
                     ->paginate($limit, ['*'], 'page', $page);
    }

    /**
     * Get company users
     */
    public function getUsers(int $companyId, int $page = 1, int $limit = 20): LengthAwarePaginator
    {
        $company = Company::find($companyId);
        if (!$company) {
            return new LengthAwarePaginator([], 0, $limit, $page);
        }

        return $company->users()
                      ->with(['roles'])
                      ->orderBy('created_at', 'desc')
                      ->paginate($limit, ['*'], 'page', $page);
    }

    /**
     * Add social link to company
     */
    public function addSocialLink(int $companyId, string $platform, ?string $handle = null, ?string $url = null): ?CompanySocial
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return null;
        }

        return $company->addSocialLink($platform, $handle, $url);
    }

    /**
     * Update social link
     */
    public function updateSocialLink(int $companyId, string $platform, ?string $handle = null, ?string $url = null): ?CompanySocial
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return null;
        }

        return $company->updateSocialLink($platform, $handle, $url);
    }

    /**
     * Remove social link
     */
    public function removeSocialLink(int $companyId, string $platform): bool
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return false;
        }

        return $company->socialLinks()->where('platform', $platform)->delete() > 0;
    }

    /**
     * Add product link to company
     */
    public function addProductLink(int $companyId, string $platform, string $url): ?CompanyProductLink
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return null;
        }

        return $company->addProductLink($platform, $url);
    }

    /**
     * Update product link
     */
    public function updateProductLink(int $companyId, string $platform, string $url): ?CompanyProductLink
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return null;
        }

        return $company->updateProductLink($platform, $url);
    }

    /**
     * Remove product link
     */
    public function removeProductLink(int $companyId, string $platform): bool
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return false;
        }

        return $company->productLinks()->where('platform', $platform)->delete() > 0;
    }

    /**
     * Get company analytics
     */
    public function getAnalytics(int $companyId): array
    {
        $company = $this->findById($companyId);
        if (!$company) {
            return [];
        }

        return $company->getStatistics();
    }

    /**
     * Bulk delete companies
     */
    public function bulkDelete(array $companyIds): int
    {
        return Company::whereIn('company_id', $companyIds)->delete();
    }

    /**
     * Get company statistics
     */
    public function getStatistics(): array
    {
        return [
            'total' => Company::count(),
            'with_users' => Company::has('users')->count(),
            'recent' => Company::recent(7)->count(),
            'avg_users_per_company' => Company::withCount('users')->avg('users_count'),
            'top_companies' => Company::withCount('users')
                                   ->orderByDesc('users_count')
                                   ->limit(5)
                                   ->get(['company_id', 'name', 'users_count'])
                                   ->toArray()
        ];
    }

    /**
     * Export companies data
     */
    public function export(array $filters = []): Collection
    {
        $query = Company::with(['users', 'socialLinks', 'productLinks'])
                       ->withCount(['users', 'activeUsers']);

        // Apply filters
        if (isset($filters['search'])) {
            $query->search($filters['search']);
        }

        return $query->get();
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit