Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/public_html/dev-test/app/Modules/Vouchers/Models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/public_html/dev-test/app/Modules/Vouchers/Models/Voucher.php
<?php
namespace App\Modules\Vouchers\Models;

use App\Modules\Vouchers\Repositories\VoucherRepository;
use Carbon\Carbon;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;

class Voucher extends Model
{

    use SoftDeletes;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table="vouchers_list";

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = ['id'];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['date_start', 'date_end'];

    /**
     * Get all of the owning voucher models.
     */
    public function parentable()
    {
        return $this->morphTo();
    }

    /**
     * Service Duration
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function service()
    {
        return $this->hasOne('App\Modules\Services\Models\ServiceDuration','id','service_id');
    }

    public function getIsValidAttribute(){
        return (int)$this->status['valid'];
    }

    /**
     * Get status
     * @return string
     */
    public function getStatusAttribute()
    {
        $status = [
            'valid'=>true,
            'message'=>'available',
        ];

        $today = Carbon::today()->timestamp;
        $min = $this->date_start->timestamp;
        $max = $this->date_end->timestamp;

        if ($today<$min){
            $status=[
                'valid'=>false,
                'message' => 'available from '.$this->date_start->format('d M Y'),
            ];
            return $status;
        }

        if ($today>$max){
            $status=[
                'valid'=>false,
                'message' => 'expired'
            ];
            return $status;
        }

        switch (class_basename($this->parentable)){
            case 'VoucherOffer':
                if ($this->max_no_usage>0){
                    $status['valid']=true;
                    $status['message']='available';
                }
                else{
                    $status['valid']=false;
                    $status['message']='used';
                }
                break;
            case 'VoucherPackage':
                break;
        } //end switch

        return $status;
    }

    /**
     * Scope by voucher code
     * @param $query
     * @param null $search
     * @return mixed
     */
    public function scopeOfVoucherCode($query,$search=null)
    {
        if ($search)
            $query->where('code', '=', $search);

        return $query;
    }

    /**
     * Scope by voucher code
     * @param $query
     * @param null $search
     * @return mixed
     */
    public function scopeOfEmail($query,$search=null)
    {
        if ($search)
            $query->where('email', '=', $search);

        return $query;
    }

}

ZeroDay Forums Mini