<?php

namespace App\Models;

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

class Orders extends Model
{
    use HasFactory;

    protected $table = 'orders';
    protected $fillable = ['user_id','total_original_amount','total_discount_amount','discount_type','discount_percentage','discount_amount','status','name', 'email', 'phone', 'address', 'city', 'state', 'country', 'pincode', 'landmark', 'payment_method', 'payment_id', 'payment_status', 'payment_request_id'];
    
    public function orderitems()
    {
        return $this->hasMany(OrderDetails::class,'order_id','id');
    }
    	
	public function user()
    {
        return $this->belongsTo(\App\Models\User::class, 'user_id');
    }
    
    public function payment_details()
    {
        return $this->hasMany(PaymentDetails::class,'order_id','id')->latest();
    }
    
    public function state_details()
    {
        return $this->belongsTo(\App\Models\State::class, 'state');
    }
    
    public function country_details()
    {
        return $this->belongsTo(\App\Models\Country::class, 'country');
    }
    
    public function city_details()
    {
        return $this->belongsTo(\App\Models\City::class, 'city');
    }
    
}
