<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel;

class Lab2 extends BaseModel
{
    use HasFactory;

    protected $table = 'labs2';

    public function address($short = false){
        $data = json_decode($this->data);
       
        $labAddress = [];
        $labAddressShort = [];

        if($data->address2) {
            $labAddress[] = $data->address2;
        }

        if($data->city) {
            $labAddress[] = '<br>' . $data->city;
            $labAddressShort[] = $data->city;
        }
        if($data->state) {
            $labAddress[] = ' ' . $data->state . ', ';
            $labAddressShort[] = $data->state;
        }
        if($data->zip_code) {
            $labAddress[] = ' ' . $data->zip_code;
            $labAddressShort[] = $data->zip_code;
        }
        $labAddress = implode('', $labAddress);
        $labAddressShort = implode(' ', $labAddressShort);
        if($short) return $labAddressShort;
        return $labAddress;
    }
    public function labData(){
        return json_decode($this->data);
    }
}
