Current File : //proc/thread-self/root/proc/self/root/home/tradevaly/demo.tradevaly.com.bd/app/Models/Company.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


class Company extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $fillable = [

        'created_user_id', 'modified_user_id', 'deleted_user_id', 'user_id', 'company_name', 

        'person_name', 'designation', 'country_id', 'city', 'mobile', 'alt_mobile', 'tel', 'email', 'alt_email', 'website', 'year_id', 'address', 

        'latitude', 'longitude', 'google_map_url', 'facebook', 'youtube', 'twitter', 'corporate_video', 'logo', 'cover_photo', 'galleries', 'brand_ids',

        'company_category_ids', 'related_company', 'short_summery', 'about_company', 'feature_company', 'special_email_offer', 

        'membership_agreements', 'package_id', 'package_buying_selling_id', 'package_banner_ad_id', 'package_lead_id', 'exp_date', 'status'
        
    ];

     public function companyWithCategoryMappings()
    {
        return $this->hasMany('App\Models\CompanyWithCategoryMapping');
    }


     public function companyWithCategoryAndProductCategoryMappings()
    {
        return $this->hasMany('App\Models\CompanyWithCategoryAndProductCategoryMapping');
    }


     public function products()
    {
        return $this->hasMany('App\Models\Product');
    }
    
    public function user()
    {
        return $this->hasOne('App\Models\User', 'id', 'created_user_id');
    }


    public function package()
    {
        return $this->hasOne('App\Models\Package', 'id', 'package_id');
    }



    protected function getCompanyList($conditions  = [])
    {   
        $data = Company::whereIn('status', [1,2])->pluck('company_name', 'id')->toArray();
        
        return $data;
    }



     protected function getCompanyListDynamicSelect($select = [],$conditions  = [])
    {   
       // dd($select);

        $data = Company::select($select)->get()->toArray();
        
        $reArrange = [];

        foreach ($data as $key => $value) {
            $reArrange[$value['id']]['company_name'] = $value['company_name'];
            $reArrange[$value['id']]['address'] = $value['address'];
            $reArrange[$value['id']]['logo'] = $value['logo'];
            $reArrange[$value['id']]['mobile'] = $value['mobile'];
            $reArrange[$value['id']]['email'] = $value['email'];
            $reArrange[$value['id']]['short_summery'] = $value['short_summery'];
            $reArrange[$value['id']]['website'] = $value['website'];
        }
        return $reArrange;
    }


    protected function getPackageNameByCompanyWise($companyId)
    {   
       // $companyId = 10;
        $data = Company::select('id', 'created_user_id', 'package_id')
            ->where('id', $companyId)
            ->where('status', '>=', 0)
                ->with (['package' => function($mm) use($companyId){
                        return $mm->select('id','name');
                }])->get();
        //dd($data->toArray());

        $reArrange = [];
        if( !empty( $data[0]['package']['name'] ) ){
            $reArrange['id'] = $data[0]['package']['id'];
            $reArrange['package_name'] = $data[0]['package']['name'];
        }else{

            $reArrange = '';  
        }

        //dd($reArrange);
        return $reArrange;

    }

    
}