<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Membership_users extends Model
{
    protected $table = 'membership_users';
    protected $fillable = [
        'user_id',
        'sale_id',
        'membership_id',
        'payment_plan_id',
        'start_date',
        'end_date',
        'is_active'
    ];

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    public function membership()
    {
        return $this->belongsTo(Membership::class, 'membership_id');
    }
    public function getStart_date()
    {
        $start = $this->attributes['start_date'] ?? null;
        return $start ? \Carbon\Carbon::parse($start)->format('Y-m-d') : null;
    }  

    public function payment_plan()
    {
        return $this->belongsTo(Payment_plan::class, 'payment_plan_id');
    }
}
