File: /var/www/vhost/disk-apps/qas.sports-crowd.com/app/Models/Experience/Experience.php
<?php
namespace App\Models\Experience;
use App\Models\Mailing\EmailTemplate;
use App\Models\Payment\PaymentGateway;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
// use Spatie\Activitylog\Traits\LogsActivity;
class Experience extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
// use LogsActivity;
// protected static $logAttributes = ['*'];
// protected static $logOnlyDirty = true;
// protected static $logName = 'experiences';
protected $fillable = [
'id',
'name',
'icon',
'short_description',
'description',
'term_cons_url',
'image',
'apply_to',
'includes',
'when',
'experience_type',
'plan_scheme',
'is_sponsored',
'start_datetime',
'total_capacity',
'available_slots',
'buy_limit',
'active',
'show_in',
'enable_raffle',
];
public function plans()
{
return $this->hasMany(ExperiencePlan::class)
->select([
'id',
'name',
'description',
'experience_id',
'type',
'available_slots',
'entries_per_purchase',
'buy_limit',
'display_index'
])
->where('type', 'experience')
->whereHas('prices')
->with(['prices' => function ($query) {
$query->orderBy('price', 'asc');
}])
->orderBy(
ExperiencePlanPrice::select('display_index')
->whereColumn('experience_plan_id', 'experience_plans.id')
->orderBy('display_index', 'asc')
->limit(1)
);
}
public function academy_plans()
{
return $this->hasMany(ExperiencePlan::class)
->select([
'id',
'name',
'description',
'experience_id',
'type',
'available_slots',
'entries_per_purchase',
'display_index'
])
->where('type', 'academy')
->whereHas('prices')
->with(['prices' => function ($query) {
$query->orderBy('price', 'asc');
}])
->orderBy(
ExperiencePlanPrice::select('price')
->whereColumn('experience_plan_id', 'experience_plans.id')
->orderBy('price', 'asc')
->limit(1)
);
}
public function paymentGateways()
{
return $this->belongsToMany(PaymentGateway::class, 'experience_gateway_payments', 'experience_id', 'gateway_payment_id')->withTimestamps();
}
public function emailTemplate()
{
return $this->belongsTo(EmailTemplate::class);
}
public function experience_erp()
{
return $this->belongsTo(ExperienceErp::class);
}
}