Current File : /home/tradevaly/demo.tradevaly.com.bd/app/Models/Package.php |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Package extends Model
{
use HasFactory;
use SoftDeletes;
protected $fillable = [
'created_user_id', 'modified_user_id', 'deleted_user_id', 'name', 'type', 'status', 'updated_at'
];
public function packageDetails()
{
return $this->hasMany('App\Models\PackageDetail');
}
public function companies()
{
return $this->hasMany('App\Models\Company');
}
protected function getPackage($conditions = [])
{
$data = Package::where('status', 1)->where($conditions)->pluck('name', 'id')->toArray();
return $data;
}
protected function getPackageWithDetails($conditions = [])
{
//dd($conditions);
$data = Package::where('status', 1)->where($conditions)
->with (['packageDetails' => function($mm){
return $mm->select('id', 'package_id', 'duration_id', 'price', 'description', 'status');
}])->get()->toArray();
return $data;
}
protected function getPackageExpireDate($conditions = [])
{
//dd($conditions);
$data = $this->getPackageWithDuration($conditions);
$duration = !empty( $data[0]['duration']['name']) ? $data[0]['duration']['name'] : 0;
$curentDate = date('Y-m-d');
$calculateExpireDate = date('d-m-Y', strtotime($curentDate. ' +'.$duration.' days'));
return $calculateExpireDate;
}
}